MDAC 2.5 SDK - ODBC Programmer's Reference
Chapter 6: Connecting to a Data Source or Driver
Before the application can connect to a data source or driver, it must allocate a connection handle, as follows:
SQLHDBC hdbc1;
SQLAllocHandle(SQL_HANDLE_DBC, henv1, &hdbc1);
The Driver Manager does not call SQLAllocHandle in the driver at this time because it does not know which driver to call. It delays calling SQLAllocHandle in the driver until the application calls a function to connect to a data source. For more information, see "Driver Manager's Role in the Connection Process," later in this chapter.
It is important to note that allocating a connection handle is not the same as loading a driver. The driver is not loaded until a connection function is called. Thus, after allocating a connection handle and before connecting to the driver or data source, the only functions the application can call with the connection handle are SQLSetConnectAttr, SQLGetConnectAttr, or SQLGetInfo with the SQL_ODBC_VER option. Calling other functions with the connection handle, such as SQLEndTran, returns SQLSTATE 08003 (Connection not open). For complete details, see Appendix B, "ODBC State Transition Tables."
For more information about connection handles, see "Connection Handles" in Chapter 4, "ODBC Fundamentals."