Driver Manager’s Role in the Connection Process
The connection process is different. When the application calls SQLAllocHandle with the SQL_HANDLE_ENV and SQL_HANDLE_DBC options, the function allocates
handles only in the Driver Manager. The Driver Manager does not call this
function in the driver, because it does not know which driver to call. Similarly, if
the application passes the handle of an unconnected connection to SQLSetConnectAttr or SQLGetConnectAttr, only the Driver Manager executes the function. It stores or gets the
attribute value from its connection handle and returns SQLSTATE 08003 (Connection not
open) when getting a value for an attribute that has not been set and for which
ODBC does not define a default value.
When the application calls SQLConnect, SQLDriverConnect, or SQLBrowseConnect, the Driver Manager first determines which driver to use. It then checks
whether a driver is currently loaded on the connection:
The Driver Manager then calls SQLAllocHandle in the driver with the SQL_HANDLE_DBC option, regardless of whether it was
just loaded. If the application set any connection attributes, the Driver Manager
calls SQLSetConnectAttr in the driver; if an error occurs, the Driver Manager
When the application calls SQLDisconnect, the Driver Manager calls SQLDisconnect in the driver. However, it leaves the driver loaded in case the application
reconnects to the driver. When the application calls SQLFreeHandle with the SQL_HANDLE_DBC option, the Driver Manager calls SQLFreeHandle in the driver. If the driver is not used by any other connections, the Driver
Manager then calls SQLFreeHandle in the driver with the SQL_HANDLE_ENV option and unloads the driver.
If no driver is loaded on the connection, the Driver Manager checks whether
the specified driver is loaded on another connection in the same environment. If
not, the Driver Manager loads the driver on the connection and calls SQLAllocHandle in the driver with the SQL_HANDLE_ENV option.
If the specified driver is loaded on the connection, the Driver Manager only
calls the connection function in the driver. In this case, the driver must make
sure that all connection attributes on the connection maintain their current
settings.
If a different driver is loaded on the connection, the Driver Manager calls SQLFreeHandle in the driver to free the connection. If there are no other connections that
use the driver, the Driver Manager calls SQLFreeHandle in the driver to free the environment and unloads the driver. The Driver
Manager then performs the same operations as when a driver is not loaded on the
connection.