How to: Add Data Binding to a Web Test

According to this walkthrough:

http://msdn2.microsoft.com/library/ms182546(en-us,vs.80).aspx

I should be able take values from a Table Column and use them as values for QueryString Parameters. In my case, I want to use them as Form Post Parameters instead of QueryString but either way, I get the same result:

First, When I add the Data Source, the thing says something like 'Invalid Object' when I try to run the test, My data Source is AdventureWorks1.vEmployee and the only way I have been able to get rid of this error is by editing the Data Source in the XML to say "HumanResources.vEmployee" in the <DataSourceTable> tag.

Second, the walkthrough says 'select the name of the field' for the Value property of the parameter. It only lets me select down to the Table level, Columns do not show up and whether I leave it like that or I add the Column Name in the XML, I get this error when I run the WebTest:

RequestFailed: Context parameter 'AdventureWorks1.HumanResources.vEmployee' not found in test case context

So I add a context parameter and basically I go through what is described in this post:

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=11208

So my questions are:

- Do I have to use a Context Parameter to feed the value from the database to the QueryString or Form Post parameters?

- If not, how do I get rid of that 'RequestFailed' error while at the same time, I use binding in the Value property of the Parameters?

- Am I going to have to generate code for what I'm doing?

Thanks in advance!

[1845 byte] By [D.OmarVillarreal] at [2007-12-17]
# 1

You should be able to bind values from a table column to a form post parameter just as you can with a QueryString parameter.

You do not have to set Context Parameters to perform databinding to a data source and you do not have to write code.

To start with I would suggest creating a new web test from scratch. You should never have to manually edit the XML and that fact that is has been manually edited means it could be corrupt.

So, start with a new web test.

Then to data bind the steps should be...
- define a data source
- define the connection string
- choose the table you want to use from this data source
- create a form post parameter on a request
- select the form post parameter tree node in the web test editor
- go to the properties window and set focus to the Value property
- click the drop down button in the property grid for the Value property
- expand the data source node to expose the table nodes, expand the table node to expose the columns, then choose the column.

That all you should need to do.

Editing the DataSourceTable XML tags was the wrong thing to do and will definately cause problems for you. Again, I suggest starting over with a new web test to eliminate any problems that might be caused by manually editing the XML.

When creating the data source you are first prompted to specify the connection to the data source. Once the connection is specified, you will be prompted to choose from the set of tables or views in that data source.

You choose the column when you actually data bind to a value in the property window. The drop down control in the property grid will show all the columns for the table you selected when creating the data source. When you select a column from this control you will have a data binding for the selected field that looks like this...

DataSourceName.TableName.ColumnName

Try this again and if you run into problems post back with more details about any errors that you encounter and we'll try to determine the cause.

Thanks,
Rick

RickPotts-MS at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 2

Thank you for your reply! The steps you describe are what I tried and re-tried and re-tried again, before I decided to change the XML directly. The problem I have had since the beginning is that in the Value filed, there are no columns, the tables are the leaf-level nodes, there do not expand any further.

This is Beta 2, by the way.

D.OmarVillarreal at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 3
Sorry for the delayed response... I just returned from a vacation today...

Is the name of the data source "AdventureWorks1.vEmployee"?

The web test editor should not allow you to create a data source name with a '.' in it because that character is reserved as a separator for a bound field (the bound field format is DataSourceName.TableName.ColumnName).

If the data source name contains the '.' character, it could explain why you're having trouble with data binding. If the data source name does contain a '.' character, I'd be interested in understanding how you were able to set the name?

Thanks,
Rick

RickPotts-MS at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 4

It looks like the name of the schema where the table was created has to be included when the table is referenced and the separator of these is the dot (.) as well; but since a picture is worth a thousand words, I got a screenshot of what the data source loks like in the web test editor. The tree-view you see there is the same I get when I try to select the field to bind to in the properties window, I never get a list of table columns.

There must be a setting or something in SQLServer I guess that lets you use the table name only, without specifying the schema but I don't know what it is. And regardless, I think VS should be able to handle this.

-Omar

D.OmarVillarreal at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 5
Omar,

Could you create a screenshot of the dialog where you're choosing the HumanResources table (this is the dialog that is displayed after specifying the data source connection)?

Also, could you post the connection string associated with the AdventureWorks1 data source (copy it from the properties grid).

Thanks,
Rick

RickPotts-MS at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 6
My bad, sorry, I had added the Schema prefix manually, but I still don't get a field or column list to select from. I even started over with a new test and the outcome is exactly the same:

Here's the Choose Tables dialog:
http://teamsystemrocks.com/photos/omars_images/picture311.aspx

That generates the following view in the webtest editor tree-view:
http://teamsystemrocks.com/photos/omars_images/picture313.aspx

but when I try to bind the Form Post Parameter, this is the tree-view I get from its Value property:
http://teamsystemrocks.com/photos/omars_images/picture312.aspx

And here's the ConnectionString:

Provider=SQLNCLI.1;Data Source=(local);Persist Security Info=True;User ID=sqluser;Initial Catalog=AdventureWorks

D.OmarVillarreal at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 7
Omar,

Thank you for the screenshots. The root problem seems to be an inability to read the column metadata for the vEmployees view in your database. I was not able to reproduce this problem with an AdventureWorks database that I have, however, it appears that I was using a different version of the AdventureWorks database (the table and view names were different than those in your screenshots).

I have put together a simple console application that I could provide that would tell us if we're able to read the column metadata from your database. If you would like to try it we might get a another clue as to why the column metadata is not being read.

If you would like to try it, do the following...
- create a new C# ConsoleApplication solution.
- paste the following code into the Main() method.

string connectionString = "Provider=SQLOLEDB.1;Data Source=vse1130;Integrated Security=SSPI;Initial Catalog=AdventureWorksDW";
string tableName = "DimEmployee";

OleDbConnection conn = new OleDbConnection(connectionString);
if (conn != null)
{
conn.Open();
DataTable fields = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, tableName, null });

foreach (DataRow field in fields.Rows)
{
Console.WriteLine(field.ItemArray[3].ToString());
}
conn.Close();
}


- include the following using lines in the source file...

using System.Data.OleDb;
using System.Data;

- Change the connection string and table name in the code to match the values for your database.
- Build, run.
- Are the column names displayed when you run this app?

Thanks,
Rick

RickPotts-MS at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 8
Omar,

I suspect the problem is that the beta code is dropping the schema name when attempting to read the column metadata. My guess is that we read the table metadata and receive "HumanResources.vEmployee" for the employee view and then try to fetch the column metadata using just "vEmployee".

I think that would explain what you're seeing. The work around for this problem would be to select only tables in the "default" schema when setting up a data source.

Thanks,
Rick

RickPotts-MS at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 9
Well, I tried your code using both, "vEmployee" and "HumanResources.vEmployee" and neither one returned any columns.

About the different versions of the DB, I am using the Beta 2 VPC handed at TechEd, I do have and AdventureworksDW database, which is the one you are using, but I am using the one named only Adventureworks (no DW).

I am now working on July CTP, I will be trying this again on this new version.

Thanks for your help!

D.OmarVillarreal at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 10

FYI: This problem persists on the RC version of VS2005.

D.OmarVillarreal at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 11
A work around for this is to create a view in the default schema which access the data in the other schemas.
slumleyMSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 12
Thank you. Is this going to be fixed by RTM?
D.OmarVillarreal at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...

Visual Studio Team System

Site Classified