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. If you are using 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 Adminstrator. 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.
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 three 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 msq8012d.dll, indicating that the application will dynamically load the Access Module at runtime:
RWDBManager::database("msq8012d.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("msq8012d.dll", "INHOUSE", "cratchitt", "scrooge", ""); |
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.