Share this page

# lr_db_connect

Connects to a database.

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

Alphabetical Listing - C Language Utility 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 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.

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:

"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.

## Example

In the following example, lr_db_connect connects to an Inventory SQL database using Oracle.

Copy code

    lr_db_connect("StepName=Connect", "ConnectionString=Provider=OraOLEDB.Oracle.1,
        Data Source=<<i>Paste the Net service name from the clipboard here</i>>; Persist Security Info=True;
           User ID=myUser;Password=myPassword", "ConnectionName=db1", "ConnectionType=OLEDB", LAST );

In the following example, lr_db_connect connects to an Inventory SQL database using SQL authentication.

Copy code

    lr_db_connect("StepName=DatabaseConnection",
            "ConnectionString=Data Source=myServer.myLab.ad;Initial Catalog=InvDatabase;Persist Security Info=True;User ID=myUser;Password=myPassword",
            "ConnectionName=InvDatabaseConnection",
            "ConnectionType=SQL",
            LAST );

In the following example, lr_db_connect connects to an Inventory SQL database using Windows authentication. Note the additional Integrated Security argument that must be specified.

Copy code

    lr_db_connect("StepName=Connect",
            "ConnectionString=Data Source=myServer\\mySoa;Integrated Security=SSPI;Password=password;User ID=DOMAIN\\UserName;Initial Catalog=soa;",
            "ConnectionName=db1",
            "ConnectionType=SQL",
            LAST );

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: