Databases and Connections
This section describes the arguments used to build a connect string to a DB2 database.
In order for a SourcePro DB application to interact with a database, an
RWDBDatabase instance must be created by calling:
RWDBManager::database(accessLib, serverName, userName,
passWord, databaseName);
All arguments are of type
RWCString. The parameters are used to build a connect string that is passed to the DB2 CLI function
SQLDriverConnect(). The string is of the form:
DSN=serverName; UID=userName; PWD=passWord; DATABASE=databaseName
Here is an explanation of each argument:
accessLib: If your DB Access Module for DB2 CLI is compiled as a shared library, provide the name of the library. See the document
Building Your Applications for information about naming conventions. If you are using a static library, supply the string
"DB2CLI".
serverName: Supply the name or alias-name of the database to which you are connecting, as found using the DB2 Command Line Processor. Or, for direct control of connection parameters, pass a full connect string of the form required by
SQLDriverConnect(); for example:
"DSN=someDataSource;UID=user;PWD=password"
In this case, the string is passed to SQLDriverConnect() without modification, and the userName, passWord and databaseName parameters are ignored.
userName: Supply the login of a valid user.
passWord: Supply the password for the user specified by
userName.
NOTE: You can instead provide a password using the callback API, which may provide more security. For more information, see Chapter 10, “Callbacks” in the DB Interface Module User’s Guide.
databaseName: Optionally supply the DB2 database name on the server when using a File DSN.
Here are several examples of connecting to a server called INHOUSE on a DB2 Common Server.
In the first example, both the user name and the password are given to provide the highest level of security. Notice that the accessLib is defined as DB2CLI, indicating that the application must be linked with the static version of the Access Module:
RWDBManager::database("DB2CLI", "INHOUSE",
"cratchitt","scrooge","");
The second example shows how to open the same database from a Windows application. In this case, the accessLib is defined as "db2<ver>12d.dll", indicating that the application will dynamically load the Access Module at runtime:
RWDBManager::database("db2<ver>12d.dll", "INHOUSE",
"cratchitt", "scrooge", "");
The final example demonstrates how to open the same database again using the Access Module as a Unix shared library at runtime:
RWDBManager::database("libdb2<ver>12d.so", "INHOUSE",
"cratchitt", "scrooge", "");
The library name shown is for Solaris and AIX.