Usage
SQLAllocHandle() is used to allocate environment, connection, statement, and
descriptor handles. An application can allocate multiple environment, connection,
statement, or descriptor handles at any time a valid InputHandle exists.
If the application calls SQLAllocHandle() with *OutputHandlePtr set to an existing
environment, connection, statement, or descriptor handle, DB2 CLI overwrites the
handle, and new resources appropriate to the handle type are allocated. There are
no changes made to the CLI resources associated with the original handle.
Return codes
v SQL_SUCCESS
v SQL_SUCCESS_WITH_INFO
v SQL_INVALID_HANDLE
v SQL_ERROR
If SQLAllocHandle() returns SQL_INVALID_HANDLE, it will set OutputHandlePtr
to SQL_NULL_HENV, SQL_NULL_HDBC, SQL_NULL_HSTMT, or
SQL_NULL_HDESC, depending on the value of HandleType, unless the output
argument is a null pointer. The application can then obtain additional information
from the diagnostic data structure associated with the handle in the InputHandle
argument.
Diagnostics
Table 3. SQLAllocHandle SQLSTATEs
SQLSTATE Description Explanation
01000 Warning. Informational message. (Function returns
SQL_SUCCESS_WITH_INFO.)
08003 Connection is closed. The HandleType argument was SQL_HANDLE_STMT or
SQL_HANDLE_DESC, but the connection handle specified by the
InputHandle argument did not have an open connection. The
connection process must be completed successfully (and the
connection must be open) for DB2 CLI to allocate a statement or
descriptor handle.
HY000 General error. An error occurred for which there was no specific SQLSTATE. The
error message returned by SQLGetDiagRec() in the *MessageText
buffer describes the error and its cause.
HY001 Memory allocation failure. DB2 CLI is unable to allocate memory required to support
execution or completion of the function. It is likely that
process-level memory has been exhausted for the application
process. Consult the operating system configuration for
information on process-level memory limitations.
HY013 Unexpected memory handling
error.
The HandleType argument was SQL_HANDLE_DBC,
SQL_HANDLE_STMT, or SQL_HANDLE_DESC; and the function
call could not be processed because the underlying memory
objects could not be accessed, possibly because of low memory
conditions.
HY014 No more handles. The limit for the number of handles that can be allocated for the
type of handle indicated by the HandleType argument has been
reached, or in some cases, insufficient system resources exist to
properly initialize the new handle.
SQLAllocHandle function (CLI) - Allocate handle
8 Call Level Interface Guide and Reference, Volume 2