Setting Connection Attributes

LabWindows/CVI SQL Toolkit 2.3 Help

Edition Date: August 2015

Part Number: 370502D-01

»View Product Info
Download Help (Windows Only)

When you set certain attributes, such as the command timeout or the isolation level, of a connection, you cannot use DBConnect because DBConnect creates and opens the connection in one step. Most attributes must be set before the connection is opened. To allow setting connection attributes, the SQL Library provides advanced functions that you can use to create and open the connection separately. You can create a connection with DBNewConnection, which has no parameters and returns a connection handle. You can then set the attributes with DBSetConnectionAttribute. The parameters of DBSetConnectionAttribute are the statement handle from DBNewConnection, the attribute to set, and the value for the attribute. You also can use DBGetConnectionAttribute to query the value of connection attributes. After you set the attributes, call DBOpenConnection to open the connection.

In some cases, instead of closing and discarding a connection with DBDisconnect, you might want to close a connection, change some attributes and reopen the connection. Use DBCloseConnection to close but not discard a connection. When you finish using the connection, discard it with DBDiscardConnection.

int hdbc = 0; /* Handle to database connection */

hdbc = DBNewConnection();

resCode = DBSetConnectionAttribute (hdbc,

ATTR_DB_CONN_DEFAULT_DATABASE, "PUBS");

... /* set additional attributes */

resCode = DBOpenConnection (hdbc);

... /* use the connection */

resCode = DBCloseConnection (hdbc);

resCode = DBDiscardConnection (hdbc);

WAS THIS ARTICLE HELPFUL?

Not Helpful