Utility Functions and C Language Reference > Utility Functions: C Language (lr_) > Alphabetical Listing > lr_db_connect

lr_db_connect

Connects to a database.

C Language

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

Example: lr_db_connect Database Functions

Arguments

Name Comments
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

  • ORACLE

LAST This delimiter marks the end of the argument list.

The lr_db_connect function establishs 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:

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

"ConnectionString=Server=soa-m16\\soa;Database=...

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.

Parameterization

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