In order for a DBTools.h++ application to open and use the connections required for interacting with a database, you must 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; PWD=passWord; DB=databaseName; UID=userName
The arguments you must provide to RWDBManager::database() are:
accessLib: If your DBTools.h++ access library is compiled as a DLL or shared library, provide the name of the DLL or shared library. See the Build Guide for information about naming conventions. If you are using a static library, supply the string "MS_SQL". This is a required parameter.
serverName: Supply the name of the SQL Server ODBC data source to which you are connecting, as found in your ODBC control panel (Windows), or your .odbc.ini file (Unix); for example, "mssql_driver". Alternatively, supply a full connect string of the form required by SQLDriverConnect(), and it will be passed to SQLDriverConnect() without modification; for example, "DSN=someDataSource;UID=user;PWD=password". This is a required argument.
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 library:
RWDBManager::database("MS_SQL", "INHOUSE", "cratchitt","scrooge","ACCOUNTING");
The second example shows opening the same database from a Windows NT or Windows 95 application. In this case, the accessLib is defined as msq4d.dll, indicating that the application will dynamically load the access library at runtime:
RWDBManager::database("msq4d.dll", "INHOUSE", "cratchitt","scrooge","ACCOUNTING");
The final example demonstrates how to open a user's default database, which is the database assigned to the user by the database administrator:
RWDBManager::database("msq4d.dll", "INHOUSE", "cratchitt", "scrooge", "");
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.