I want to enable connection pooling in my DB2 CLI application, and have followed the steps outline in ftp://ftp.software.ibm.com/ps/produc...S/db2l2e81.pdf, which describes how to set the SQL_ATTR_CONNECTION_POOLING attribute.

The documentation specifically states that SQLSetEnvAttr must be called with a NULL environment handle. However, when I do this, I get a SQL_INVALID_HANDLE return code, and the connection pooling attribute value does not change (it retains the default value, SQL_CP_OFF). This is how I am using SQLSetEnvAttr to set the connection pooling attribute:

cliRC = SQLSetEnvAttr (
SQL_NULL_HANDLE, // Environment Handle
SQL_ATTR_CONNECTION_POOLING, // Pooling attribute name
SQL_CP_ONE_PER_HENV, // Pooling attribute value
0); // Ignored in this context
// Note: Connection pooling applies for the entire process, hence null handle.

// Next step is to allocate an environment handle
cliRC = SQLAllocHandle (

This is the relevant section of the documentation:

Environment attributes (CLI) list
Note: ODBC does not support setting driver-specific environment attributes using SQLSetEnvAttr(). Only CLI applications can set the DB2 CLI-specific environment attributes using this function.


32-bit integer value that enables or disables CLI connection pooling at the environment level. If an ODBC application sets this value, connection pooling at the ODBC Driver Manager will be enabled, not at the CLI level. Only applications written to access CLI directly can set this environment attribute to control CLI connection pooling. The following values are used:

SQL_CP_OFF = Connection pooling is turned off. This is the default.

SQL_CP_ONE_PER_DRIVER = A single, global connection pool is supported for each DB2 CLI application. Every connection in a pool is associated with the application.

SQL_CP_ONE_PER_HENV = A single connection pool is supported for each environment. Every connection in a pool is associated with one environment.

Connection pooling is enabled by calling SQLSetEnvAttr() to set the SQL_ATTR_CONNECTION_POOLING attribute to SQL_CP_ONE_PER_DRIVER or SQL_CP_ONE_PER_HENV.
The environment handle in the call to SQLSetEnvAttr() is set to null, which makes SQL_ATTR_CONNECTION_POOLING a process-level attribute. After connection pooling is enabled, the application then allocates an implicit shared environment by calling SQLAllocHandle() with the InputHandle argument set to SQL_HANDLE_ENV. After connection pooling has been enabled and a shared environment has been selected for an application, SQL_ATTR_CONNECTION_POOLING cannot be reset for that environment, since SQLSetEnvAttr() is called with a null environment handle when setting this attribute. If this attribute is set while connection pooling is already enabled on a shared environment, the attribute only affects shared environments that are allocated subsequently.