none
VS2015 Web Performance Test - How to update database

    Question

  • Hi folks,

     In a Web Performance test, once a row has been read from the database and the test iteration for it completed, how do I update the same row in the database. I would like to update a datetime field with the execution time, but do not want to use a separate table.

    Tuesday, March 21, 2017 1:01 AM

Answers

  • Hi AndyW2007,

    We could implement with web test plugin, first you need to know how to create web test plugin for web test plugin, please refer to the following MSDN document:

    https://msdn.microsoft.com/en-us/library/ms243191.aspx?f=255&MSPPError=-2147217396

    Add the following code to web test plugin:

            object contextParameterObject;
            public override void PostWebTest(object sender, PostWebTestEventArgs e)
            {
                if (e.WebTest.Context.TryGetValue("DataSource1.Colors.ColorID",
                    out contextParameterObject))//get ID from using table
                {
                    string contextParameter = contextParameterObject.ToString();
                    e.WebTest.AddCommentToResult(contextParameter);
                    MessageBox.Show(contextParameter);
                }
                else
                {
                    throw new WebTestException("'DataSource1.Colors.ColorID' not found");
                }
                //here you could operate the database with "ColorID", and insert the current datetime
            }

    And make sure we have selected the Select all columns:

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by qing__Moderator Thursday, March 23, 2017 8:52 AM
    • Marked as answer by AndyW2007 Thursday, May 18, 2017 9:27 PM
    Wednesday, March 22, 2017 2:41 AM
    Moderator

All replies

  • Hi AndyW2007,

    We could implement with web test plugin, first you need to know how to create web test plugin for web test plugin, please refer to the following MSDN document:

    https://msdn.microsoft.com/en-us/library/ms243191.aspx?f=255&MSPPError=-2147217396

    Add the following code to web test plugin:

            object contextParameterObject;
            public override void PostWebTest(object sender, PostWebTestEventArgs e)
            {
                if (e.WebTest.Context.TryGetValue("DataSource1.Colors.ColorID",
                    out contextParameterObject))//get ID from using table
                {
                    string contextParameter = contextParameterObject.ToString();
                    e.WebTest.AddCommentToResult(contextParameter);
                    MessageBox.Show(contextParameter);
                }
                else
                {
                    throw new WebTestException("'DataSource1.Colors.ColorID' not found");
                }
                //here you could operate the database with "ColorID", and insert the current datetime
            }

    And make sure we have selected the Select all columns:

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by qing__Moderator Thursday, March 23, 2017 8:52 AM
    • Marked as answer by AndyW2007 Thursday, May 18, 2017 9:27 PM
    Wednesday, March 22, 2017 2:41 AM
    Moderator
  • Hi friend,

    If my reply help you resolved your issue, would you please mark it as answer, which could help others who has the same issue as you.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 24, 2017 1:47 AM
    Moderator