ASA Programming Guide
ODBC Programming
ODBC handles
The handle types required for ODBC programs are as follows:
Item | Handle type |
---|---|
Environment |
SQLHENV
|
Connection |
SQLHDBC
|
Statement |
SQLHSTMT
|
Descriptor |
SQLHDESC
|
To use an ODBC handle
Call the SQLAllocHandle function.
SQLAllocHandle takes the following parameters:
an identifier for the type of item being allocated
the handle of the parent item
a pointer to the location of the handle to be allocated
For a full description, see SQLAllocHandle in the Microsoft ODBC Programmer's Reference.
Use the handle in subsequent function calls.
Free the object using SQLFreeHandle.
SQLFreeHandle takes the following parameters:
an identifier for the type of item being freed
the handle of the item being freed
For a full description, see SQLFreeHandle in the Microsoft ODBC Programmer's Reference.
The following code fragment allocates and frees an environment handle:
SQLHENV env; SQLRETURN retcode; retcode = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env ); if( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO ) { // success: application code here } SQLFreeHandle( SQL_HANDLE_ENV, env );
For more information on return codes and error handling, see Handling errors.