This section describes the arguments used to build a connect string to an ODBC database. In order for a DBTools.h++ 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. 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; PWD=passWord; DB=databaseName; UID=userName
The arguments you must provide to RWDBManager::database() are:
accessLib: If your DBTools.h++ access library for ODBC 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 "ODBC". This is a required parameter.
serverName: Supply the name of the ODBC data source to which you are connecting, as found in your ODBC control panel (Windows), or your .odbc.ini file (Unix); for example, "dbase_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 parameter.
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.
databaseName: This parameter is optional, and its interpretation depends on the underlying driver. For example, the argument refers to a database when using a Microsoft SQL Server driver and to a directory when using a Paradox driver.
Here are several examples of opening a database.
The first example uses a driver to access dBase tables found in the \dbfiles directory. A user name and password are not necessary. Notice that accessLib is defined as "odb4d.dll", indicating that the application will dynamically load (DLL) the access library at runtime:
RWDBDatabase aDB = RWDBManager::database ("odb4d.dll", "dbase_driver", "","", "\\dbfiles");
The second example uses a driver to access Paradox tables found in the c:\paradox directory. 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 library:
RWDBDatabase aDB = RWDBManager::database ("ODBC", "paradox files", "","", "C:\\paradox");
The third example uses a driver to access Microsoft Access tables found in the e:\access directory. Again, a user name and password are not provided as they are unnecessary. Notice that accessLib is defined as "odb4d.dll", indicating that the application will dynamically load (DLL) the access library at runtime:
RWDBDatabase aDB = RWDBManager::database ("odb4d.dll", "Microsoft Access Databases", "","", "E:\\access");
The fourth example uses a driver to access Microsoft and Sybase SQL servers. A user name and password are provided, as well as a database: "ACCOUNTING". Notice that accessLib is defined as "odb4d.dll", indicating that the application will dynamically load (DLL) the access library at runtime:
RWDBDatabase aDB = RWDBManager::database ("odb4d.dll", "Microsoft/Sybase SQL Server", "cratchitt","scrooge", "ACCOUNTING");
The final example uses a driver on a Unix machine to access Sybase SQL servers. Notice that accessLib is defined as "libodb4d.so", indicating that the application will use the access library as a Unix shared library at runtime:
RWDBDatabase aDB = RWDBManager::database ("libodb4d.so", "Sybase", "cratchitt","scrooge", "ACCOUNTING");
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.