Connects to a database.

C Language

int lr_db_connect("StepName", "ConnectionString=<connection_string>", "ConnectionName=<connection_name>", "ConnectionType=<connection_type>", LAST );

Example: lr_db_connectDatabase Functions


StepName The name of the step, as it appears in the test tree. Any text can be used.
ConnectionString A string indicating the database to which to connect and other information needed to establish the connection. The syntax for the connection string varies depending on the data provider specified with the ConnectionType argument. For example, to connect to an SQL Server, ConnectionString could contain the value: Data Source=myServerAddress; Initial Catalog=myDatabase Id=myUser;Password=myPassword; Note that the equal signs are part of the connection string. The password cannot be encrypted.
ConnectionName A logical name for the connection.
ConnectionType Type of data provider. Valid values are:
  • SQL (meaning, the Microsoft Native SQL Provider)

  • OLEDB (use OLEDB for Oracle)

  • ODBC


LAST This delimiter marks the end of the argument list.

The lr_db_connect function establishes the database connection used by other database related functions, such as lr_db_executeSQLStatement.

This function is supported only under the Windows operating system.

Tip: Use the Connection Dialog to create a database specific connection string. Select the Database: Connect option in the Add Step dialog box and enter the connection parameters.

When specifying a connection string for Oracle, make sure to:

  • Specify a ConnectionType of OLEDB.

  • Configure Oracle clients before using this function. See the information about configuring Oracle environments in the Virtual User Generator Help Center (select the relevant version).

When specifying the connection string for a specific SQL Server instance, use the server and instance name in the data source, escaping the backslashes in the path. For example:


When specifying the connection string using SQL Server 2005 Express, use the server name syntax <SQL Server 2005 Express installation>\SQLEXPRESS.

Add lr_db_connect to the vuser_init section of the script. Adding this function to the Action section can increase performance overhead during load testing.

Return Values

This function always returns zero.


All string arguments (char type) can be parameterized using standard parameterization.