Databases Reference
In-Depth Information
4.5.4 Connecting and disconnect to and from a database
Table 4-8 lists some APIs that can be used in working with a connection to a
database.
Table 4-8 Connection-related CLI APIs
CLI API
Purpose
SQLConnect
Connect to a database given a database name, user ID, and
password.
SQLDriverConnect
Connect to a database (has expanded connection
parameters).
SQLBrowseConnect
Use iterative method to connect to a database.
SQLSetConnectAttr
Set connection attributes.
SQLSetConnection
Sets the current active connection. Used for embedded
SQL modules within a CLI application.
SQLGetConnectAttr
Get connection option value.
SQLDisconnect
Disconnect from the database.
There are various APIs to choose from for connecting to a database. The
SQLDriverConnect() API expands the functionality of SQLConnect() by allowing
extra connection parameters and the ability to get connection information from
the user. The SQLBrowseConnect() is an iterative way of connecting to the
database. In our application, we use the SQLConnect( ) API:
SQLRETURN SQLConnect (
SQLHDBC ConnectionHandle, /* hdbc */
SQLCHAR *ServerName, /* szDSN */
SQLSMALLINT ServerNameLength, /* cbDSN */
SQLCHAR *UserName, /* szUID */
SQLSMALLINT UserNameLength, /* cbUID */
SQLCHAR *Authentication, /* szAuthStr */
SQLSMALLINT AuthenticationLength); /* cbAuthStr */
In our code, we add the following line (Example 4-33 on page 186) to establish a
default database connection and later to disconnect from the database.
 
Search WWH ::




Custom Search