Using SilkTest Workbench how can I create a Data Driven test using VB.Net which will read data from a SQL Server Database?

In the SilkTest Workbench you can create a VB.NET script which utilises the native VB.NET Framework in order to connect to a database, execute a query  and return the output of the query. Once the data is returned it can then be passed as parameters to the various SilkTest methods in order to populate the Application under Test with dynamic data.

The steps to implement such an approach are as follows:

1) Ensure that the SQL Server database is configured for communication via the TCP/IP protocol; this can be done by ensuring TCP/IP is set to enabled by going to:

Start | Programs | Microsoft SQL Server 200X |  SQL Server Configuration Manager | SQL Network Configuration and Selecting the Database and viewing its properties.

2) Create a new .NET Script from the SilkTest Workbench

3) Add a Reference for System.Data; this DLL allows you to use the classes required for connecting to a SQL Server Database

Under Properties, Select References, Right Click and Choose “Add Reference




Choose Browse and locate the DLL System.Data.Dll. In my installation this DLL was found in the following directory:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

4) Add a Reference for System.XML; this DLL allows you to use the classes required for retrieving and storing the data from the database using a data set.

Choose Browse and locate the DLL System.XML.DLL. In my installation this DLL was found in the following directory:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

5) Add imports for the following classes at the top of your .NET script:

Imports System.Data
Imports System.Data.SqlClient

6) Use the test case shown below as an example of how to create the connection to the SQL Server database using the native VB.NET framework.



Some important things to note are:

• The SQL Server database does not have to reside on the same machine as SilkTest workbench, it only has to be accesible via TCP/IP
• To force the VB.NET engine to use a TCP/IP connection to the database you have to specify the paramater “Network Library=DBMSSOCN” in the connection string
• To save the returned data from the database you will need to create a new data set object; like so:

    Dim RetData As New System.Data.DataSet

• To force the SilkTest test case to be a data driven test and execute the actual test case for each user in the database table, you will need to encapsulate the SilkTest test case code within the code below as demonstrated in the above screen shot:

    For I=0 To RetData.Tables(0).Rows.Count-1

   This will have the affect of iterating through all users in the table