f90SQLDriverConnect is used to connect to a data source using a connection string. f90SQLDriverConnect is used instead of f90SQLConnect for the following reasons:
f90SQLConnect assumes that a data source name, user ID, and password are sufficient to connect to a data source, and that all other connection information can be stored on the system. This is often not the case. For example, a driver might need one user ID and password to log into a server and a different user ID and password to log into a DBMS. Because f90SQLConnect accepts a single user ID and password, this means that the other user ID and password must be stored with the data source information on the system if f90SQLConnect is to be used. This is a potential breach of security and should be avoided unless the password is encrypted.
f90SQLDriverConnect allows the driver to define an arbitrary amount of connection information in the keyword-value pairs of the connection string. For example, suppose a driver requires a data source name, a user ID and password for the server, and a user ID and password for the DBMS. A custom program that always uses the XYZ Corp data source might prompt the user for IDs and passwords and build the following set of keyword-value pairs to for f90SQLDriverConnect:
DSN=XYZ Corp;UID=Gomez;PWD=Sesame;UIDDBMS=JGomez;PWDDBMS=Shazam;
The DSN (Data Source Name) keyword names the data source. The UID and PWD keywords specify the user ID and password for the server. The UIDDBMS and PWDDBMS keywords specify the user ID and password for the DBMS. Note that the final semicolon is optional. f90SQLDriverConnect parses this string; uses the XYZ Corp data source name to retrieve additional connection information from the system, such as the server address; and logs on to the server and DBMS using the specified user IDs and passwords.
Keyword-value pairs in f90SQLDriverConnect must follow certain syntax rules. The keywords and their values should not contain the []{}(),;?*=!@ characters. The value of the DSN keyword cannot consist only of blanks, and should not contain leading blanks. Because of the registry grammar, keywords and data source names cannot contain the backslash (\) character. Spaces are not allowed around the equal sign in the keyword-value pair.
The FILEDSN keyword can be used in a call to f90SQLDriverConnect to specify the name of a file containing data source information (see "Connecting Using File Data Sources" later in this section). The SAVEFILE keyword can be used to specify the name of a .dsn file. This file can store the keyword-value pairs of a successful connection made by a call to f90SQLDriverConnect.
The short program in Example 5.1 establishes two connections to data sources selected by the user from a list of available data sources. The example illustrates how to use f90SQLDriverConnect in two different forms. To connect to the first data source, we call f90SQLDriverConnect with the option SQL_DRIVER_COMPLETE. This forces the driver to request connection information from the user. Note that this is done by the driver, no by the application. To connect to the second data source, the application requests the user ID and password and builds a connection string. In this second case, we use the option SQL_DRIVER_NOPROMPT with f90SQLDriverConnect. If the user enters an invalid user ID or password, the connection is not established.
|
Some applications may not want to use a data source at all. Instead, they may want to connect directly to a driver. f90SQLDriverConnect provides a way for the application to connect directly to a driver without specifying a data source. Conceptually, a temporary data source is created at run time.
To connect directly to a driver, the application specifies the DRIVER keyword in the connection string instead of the DSN keyword. The value of the DRIVER keyword is the description of the driver as returned by f90SQLDrivers. For example, suppose a driver has the description "Paradox Driver", and requires the name of a directory containing the data files. To connect to this driver, the application might use either of the following connection strings:
DRIVER={Paradox Driver};Directory=C:\PARADOX;
DRIVER={Paradox Driver};
With the first string, the driver would not need any additional information. With the second string, the driver would need to prompt for the name of the directory containing the data files.