Databases and Connections
In order for a SourcePro DB application to open and use the connections required for interacting with a database, create an RWDBDatabase instance by calling:
 
RWDBManager::database(accessLib, serverName, userName,
passWord, databaseName);
These arguments, which are all of type RWCString, are used to build a connect string that is passed to the ODBC API function SQLDriverConnect(). This string takes the form:
 
DSN=serverName; UID=userName; PWD=passWord; DATABASE=databaseName;
The arguments you must provide to RWDBManager::database() are:
*accessLib: If your DB Access Module for Microsoft SQL Server 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. For a static library, supply the string "MS_SQL".
*serverName: Supply the name of the SQL Server 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 the login of a valid user. Depending on the ODBC SQL Server data source settings, this may or may not be optional.
*passWord: Supply the password for the user specified by userName. Depending on the Microsoft SQL Server ODBC data source settings, 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: You can optionally supply the name of a SQL server database to use. If this parameter is not supplied, the default database of the specified user is used.
Here are four examples of opening a database on a specific SQL server, INHOUSE.
*The first example opens a specific database, ACCOUNTING. Notice that the accessLib is defined as MS_SQL, indicating that the application must be linked with the static version of the Access Module:
 
RWDBManager::database("MS_SQL", "INHOUSE",
"cratchitt","scrooge","ACCOUNTING");
*The second example shows opening the same database from a Windows application. In this case, the accessLib is defined as msq<ver>12d.dll, indicating that the application will dynamically load the Access Module at runtime:
 
RWDBManager::database("msq<ver>12d.dll", "INHOUSE",
"cratchitt","scrooge","ACCOUNTING");
*The third example demonstrates how to open a user’s default database, which is the database assigned to the user by the database administrator:
RWDBManager::database("msq<ver>12d.dll", "INHOUSE",
"cratchitt", "scrooge", "");
*The final example demonstrates how to open the same database again using the Access Module as a Linux shared library at runtime (note the .so extension in the library name):
RWDBManager::database("libmsq<ver>12d.so", "INHOUSE",
"cratchitt", "scrooge", "");