DB Access Module for ODBC User’s Guide : Chapter 2 Technical Information : Databases and Connections
Databases and Connections
This section describes the arguments used to build a connect string to an ODBC 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, "");
All arguments are of type RWCString. These parameters are used to build a connect string which is passed to the ODBC API function SQLDriverConnect(). The string is of the form:
DSN=serverName; UID=userName; PWD=passWord;
The arguments you must provide to RWDBManager::database() are:
accessLib: If your DB Access Module for ODBC is compiled as a DLL or shared library, provide the name of the DLL or shared library. See the document Building Your Applications for information about naming conventions. If you are using a static library, supply the string “ODBC”.
serverName: Supply the name of the ODBC data source to which you are connecting, as found in the ODBC Data Source Administrator. 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 a login of a valid user. Depending on the underlying driver, this may or may not be optional.
passWord: Supply the password for the user specified by userName. Depending on the underlying driver, this may or may not be optional.
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: Note: This parameter is deprecated. If a value is supplied, it is used to form a portion of the connect string by appending “;DB=databaseName” to the connect string. The interpretation of this argument is driver dependent as it is not a connection keyword in the ODBC API.
Here are several examples of opening a database.
The first example uses a driver to access dBase tables. A user name and password are not necessary. Notice that accessLib is defined as “odb<ver>12d.dll”, indicating that the application will dynamically load (DLL) the Access Module at runtime:
 
RWDBDatabase aDB = RWDBManager::database ("odb<ver>12d.dll",
"dbase_driver", "","", "");
The second example uses a driver to access Paradox tables. Again, a user name and password are unnecessary, and omitted. Notice that accessLib is defined as “ODBC”, indicating that the application must be linked with the static version of the Access Module:
 
RWDBDatabase aDB = RWDBManager::database ("ODBC",
"paradox files", "","", "");
The third example uses a driver to access a Microsoft database server named “Microsoft SQL Server”. A user name and password are provided. Notice that accessLib is defined as “odb<ver>12d.dll”, indicating that the application will dynamically load (DLL) the Access Module at runtime:
 
RWDBDatabase aDB = RWDBManager::database ("odb<ver>12d.dll",
"Microsoft SQL Server",
"cratchitt","scrooge", "");
The final example uses a driver on a Unix machine to access a Sybase ASE server with a Data Source Name of “Sybase”. Notice that accessLib is defined as “libodb<ver>12d.so”, indicating that the application will use the Access Module as a UNIX shared library at runtime:
 
RWDBDatabase aDB = RWDBManager::database ("libodb<ver>12d.so",
"Sybase",
"cratchitt","scrooge", "");