Handles
A handle is a variable that refers to a data object that is controlled by Db2 ODBC. The environment, connection, and statement handles are necessary for the initialization and termination processes.
Using handles relieves the application from managing global variables or data structures, such as the SQLDA or SQLCA, that the IBM® embedded SQL interfaces use.
- Environment handle
- The environment handle refers to the data object that contains
information regarding the global state of the application, such as
attributes and connections. This handle is allocated by calling
SQLAllocHandle()(with HandleType set to SQL_HANDLE_ENV), and freed by callingSQLFreeHandle()(with HandleType set to SQL_HANDLE_ENV). An environment handle must be allocated before a connection handle can be allocated. - Connection handle
- A connection handle refers to a data object that contains information
associated with a connection to a particular data source. This includes
connection attributes, general status information, transaction status,
and diagnostic information. Each connection handle is allocated by
calling
SQLAllocHandle()(with HandleType set to SQL_HANDLE_DBC) and freed by callingSQLFreeHandle()(with HandleType set to SQL_HANDLE_DBC).An application can be connected to several database servers at the same time. An application requires a connection handle for each concurrent connection to a database server.
Call
SQLGetInfo()to determine if a user-imposed limit on the number of connection handles has been set. - Statement handles
- A statement handle refers to the data object that describes and
tracks the execution of an SQL statement. You can allocate a statement
handle by calling
SQLAllocHandle()and must do so before you can execute a statement.
The initialization task consists of the allocation and initialization of environment and connection handles. The termination task later frees these handles. An application then passes the appropriate handle when it calls other Db2 ODBC functions.