Specification: | DB2 CLI 2.1 | ISO CLI |
SQLSetEnvAttr() sets an environment attribute for the current environment.
Syntax
SQLRETURN SQLSetEnvAttr (SQLHENV EnvironmentHandle, /* henv */ SQLINTEGER Attribute, SQLPOINTER ValuePtr, /* Value */ SQLINTEGER StringLength);
Function Arguments
Table 162. SQLSetEnvAttr Arguments
Data Type | Argument | Use | Description |
---|---|---|---|
SQLHENV | EnviornmentHandle | Input | Environment handle. |
SQLINTEGER | Attribute | Input | Environment attribute to set, refer to Table 163 for the list of attributes and their descriptions. |
SQLPOINTER | ValuePtr | Input | The desired value for Attribute. |
SQLINTEGER | StringLength | Input | Length of ValuePtr in bytes if the attribute value is a character string; if Attribute does not denote a string, then DB2 CLI ignores StringLength. |
Usage
Once set, the attribute's value affects all connections under this environment.
The application can obtain the current attribute value by calling
SQLGetEnvAttr().
Table 163. Environment Attributes
Attribute | Contents | ||
---|---|---|---|
SQL_ATTR_CONNECTION_POOLING |
32-bit integer value that enables or disables connection pooling at the environment level. The following values are used:
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. This call must be made before the application allocates the shared environment for which connection pooling is to be enabled. 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.
| ||
SQL_ATTR_CONNECTTYPE | A 32-bit integer value that specifies whether this application is to
operate in a coordinated or uncoordinated distributed environment. If the
processing needs to be coordinated, then this option must be considered in
conjunction with the SQL_ATTR_SYNC_POINT connection option. The possible
values are:
This attribute must be set before allocating any connection handles, otherwise, the SQLSetEnvAttr() call will be rejected. All the connections within an application must have the same SQL_ATTR_CONNECTTYPE and SQL_ATTR_SYNC_POINT values. This attribute can also be set using the SQLSetConnectAttr function. We recommend that the application set the SQL_ATTR_CONNECTTYPE attribute at the environment level rather than on a per connection basis. ODBC applications written to take advantage of coordinated DB2 transactions must set these attributes at the connection level for each connection using SQLSetConnectAttr() as SQLSetEnvAttr() is not supported in ODBC.
| ||
SQL_ATTR_CP_MATCH | A 32-bit value that determines how a connection is chosen from a
connection pool. When SQLConnect() or
SQLDriverConnect()is called, DB2 CLI (or the Driver Manager
when used) determines which connection is reused from the pool. DB2 CLI (or
the Driver Manager) attempts to match the connection options in the call and
the connection attributes set by the application to the keywords and
connection attributes of the connections in the pool. The value of this
attribute determines the level of precision of the matching criteria.
The following values are used to set the value of this attribute:
| ||
SQL_ATTR_MAXCONN | A 32-bit integer value corresponding to the number that maximum
concurrent connections that an application may desire to set up. The default
value is 0, which means no maximum - the application is allowed to
set up as many connections as the system resources permit. The integer value
must be 0 or a positive number.
This can be used as a governor for the maximum number of connections on a per application basis. On OS/2, if the NetBIOS protocol is in use, this value corresponds to the number of connections (NetBIOS sessions) that will be concurrently set up by the application. The range of values for OS/2 NetBIOS is 1 to 254. Specifying 0 (the default) will result in 5 reserved connections. Reserved NetBIOS sessions cannot be used by other applications. The number of connections specified by this parameter will be applied to any adaptor that the DB2 NetBIOS protocol uses to connect to the remote server (adapter number is specified in the node directory for a NetBIOS node). The value that is in effect when the first connection is established is the value that will be used. Once the first connection has been established, attempts to change this value will be rejected. We recommended that the application set SQL_ATTR_MAXCONN at the environment level rather then on a connection basis. ODBC applications must set this attribute at the connection level since SQLSetEnvAttr() is not supported in ODBC.
| ||
SQL_ATTR_ODBC_VERSION | A 32-bit integer that determines whether certain functionality exhibits
ODBC 2.x (DB2 CLI v2) behavior or ODBC 3.0 (DB2 CLI v5) behavior.
It is recommended that all DB2 CLI applications set this environment attribute. ODBC applications must set this environment attribute before calling any function that has an SQLHENV argument, or the call will return SQLSTATE HY010 (Function sequence error.). The following values are used to set the value of this attribute:
| ||
SQL_ATTR_OUTPUT_NTS | A 32-bit integer value which controls the use of null-termination in
output arguments. The possible values are:
The CLI functions affected by this attribute are all functions called for the environment (and for any connections and statements allocated under the environment) that have character string parameters. This attribute can only be set when there are no connection handles allocated under this environment. | ||
SQL_ATTR_SYNC_POINT | A 32-bit integer value that allows the application to choose between
one-phase coordinated transactions and two-phase coordinated transactions. The
possible values are:
Refer to the SQL Reference for more information on distributed unit of work (transactions). All the connections within an application must have the same SQL_ATTR_CONNECTTYPE and SQL_ATTR_SYNC_POINT values. This attribute can also be set using the SQLSetConnectAttr() function. We recommend that the application set these two attributes at the environment level rather than on a per connection basis. ODBC applications written to take advantage of coordinated DB2 transactions must set these attributes at the connection level for each connection using SQLSetConnectAttr() as SQLSetEnvAttr() is not supported in ODBC.
| ||
SQL_CONNECTTYPE | This Attribute has been replaced with SQL_ATTR_CONNECTTYPE. | ||
SQL_MAXCONN | This Attribute has been replaced with SQL_ATTR_MAXCONN. | ||
SQL_SYNC_POINT | This Attribute has been replaced with SQL_ATTR_SYNC_POINT. |
Return Codes
Diagnostics
Table 164. SQLSetEnvAttr SQLSTATEs
SQLSTATE | Description | Explanation |
---|---|---|
HY009 | Invalid argument value. | Given the fOption value, an invalid value was specified for the argument vParam. |
HY011 | Operation invalid at this time. | Applications cannot set environment attributes while connection handles are allocated on the environment handle. |
HY024 | Invalid attribute value | Given the specified Attribute value, an invalid value was specified in *ValuePtr. |
HY090 | Invalid string or buffer length | The StringLength argument was less than 0, but was not SQL_NTS. |
HY092 | Option type out of range. | An invalid Attribute value was specified. |
HYC00 | Driver not capable. | The specified Attribute is not supported by DB2 CLI.
Given specified Attribute value, the value specified for the argument ValuePtr is not supported. |
Restrictions
None.
See also "Distributed Unit of Work Example".
/* From CLI sample seteattr.c */ /* ... */ int main() { SQLHANDLE henv ; SQLRETURN rc ; SQLINTEGER output_nts = SQL_TRUE ; /* ... */ /* allocate an environment handle */ rc = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv ) ; if ( rc != SQL_SUCCESS ) return( terminate( henv, rc ) ) ; printf( "Setting Environment option SQL_ATTR_OUTOUT_NTS\n" ) ; rc = SQLSetEnvAttr( henv, SQL_ATTR_OUTPUT_NTS, ( SQLPOINTER ) output_nts, SQL_FALSE ) ; CHECK_HANDLE( SQL_HANDLE_ENV, henv, rc ) ; rc = SQLFreeHandle( SQL_HANDLE_ENV, henv ) ; if ( rc != SQL_SUCCESS ) return( terminate( henv, rc ) ) ; return( SQL_SUCCESS ) ; } /* end main */
References