Setting the environment and connection handles

SQLAllocHandle is called (once) with a handle type of SQL_HANDLE_ENV to initialize the ODBC environment. The value of the Tcl variable, passed as an argument, is set on return from the function to the Tcl environment handle. For example, "henv0."

odbc SQLAllocHandle SQL_HANDLE_ENV SQL_NULL_HANDLE \ 
    henv   

SQLSetEnvAttr is then typically called to declare the application’s ODBC version. SQL_OV_ODBC3 is the most current.

odbc SQLSetEnvAttr $henv SQL_ATTR_ODBC_VERSION \
     SQL_OV_ODBC3 0   

SQLAllocHandle is finally called to allocate memory for a connection handle. The value of the Tcl variable passed as the last argument is set on return to the Tcl connection handle.

odbc SQLAllocHandle SQL_HANDLE_DBC $henv hdbc