ODBC Components

ODBC is composed of four components: the application, the driver manager, one or more drivers, and one or more data sources. ODBC can be difficult to work with because some of these components are supplied with the operating system, some are provided by the database vendor, and some are provided by the application vendor. When troubleshooting ODBC, pinning down exactly what part of the system is causing the problem can be difficult. Figure 8-4 shows the relationship of the four ODBC components and the network boundary that sometimes separates the driver from the data source.

Figure 8-4 The relationship of the four components of ODBC.

The Application

The application component of ODBC is the portion of the code that resides in the application and calls the ODBC API. The code in the application is responsible for selecting the data source to be used, submitting SQL statements for execution, retrieving results, and processing errors. The application might also configure the ODBC data sources.

Using the ODBC API can be daunting, but this task can be made easier by the use of class libraries that hide the details of implementation, allow clean access to the data retrieved, and provide error-handling capabilities. MFC offers two sets of classes that provide direct and indirect access to ODBC data sourcesthe CDatabase class and the CDAODatabase class respectivelybut neither set will be covered here. Later in this chapter we will discuss the issues associated with creating a generic wrapper around the ODBC API.

The Driver Manager

The Driver Manager is the component of ODBC that manages communication between the application and the ODBC drivers. In the Windows environment, the Driver Manager is implemented as one or more DLLs that are provided by Microsoft; it is part of the ODBC SDK and can be freely distributed. Today virtually all corporate machines have ODBC installed. The Driver Manager component is primarily a convenience to the developer. It provides a convenient , single set of functions that are called to access the various ODBC drivers. Rather than maintaining a list of pointers for each driver in use, an application can simply use the functions in the ODBC Driver Manager for any ODBC driver. The Driver Manager also performs some parameter checking to ensure that handles passed in are not NULL pointers and that functions are called in the correct order.

Another major task of the Driver Manager is to manage the loading and unloading of drivers. The application loads and unloads only the Driver Manager. The Driver Manager then loads the proper driver (if it is not already loaded) based on its search of the data source information stored in the registry. Once the driver is loaded, the Driver Manager calls the connection function in the driver, and the connection is made. When the request to disconnect from a driver is received, the Driver Manager might delay the actual unloading of the driver because once one connection is broken, another connection that could use the loaded driver can be requested . The operating system vendorin the case of Windows 2000, Microsoftprovides this component of ODBC.

The Drivers

The drivers component of ODBC consists of one or more vendor-supplied DBMS-specific drivers, which are contacted by the Driver Manager on behalf of the application. Drivers have two basic architectures. The first is used by file-based DBMS systems. In this architecture, the driver retrieves the data. Examples of this kind of system include Borland dBASE and Microsoft Access. The other major driver architecture is the server-based architecture. This driver passes the requests from the application (by way of the Driver Manager) to another database engine for processing. The database engine can reside either on the machine where the request originates or on another machine.

Drivers are responsible for sending and receiving data, mapping DBMS-specific errors to ODBC SQLSTATES, connecting and disconnecting from the data sources, and checking for errors not detected by the Driver Manager.

The Data Sources

The data sources are the final component of ODBC. A data source is specific to each DBMS. The data source can be a file (similar to a file-based DBMS such as Access) or a database on a database server. It can also be a machine data source, which is stored on a single system using a user -defined name or a file data source the same information is stored in both amachine data source and a file data source. The file can be stored on a network-accessible drive and shared, or it can be unshared and located on a local drive pointing to a local machine data source. Each DBMS vendor provides a data source for its product.



Inside Server-Based Applications
Inside Server-Based Applications (DV-MPS General)
ISBN: 1572318171
EAN: 2147483647
Year: 1999
Pages: 91

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net