SQLSetEnvAttr() - Set environment attributes
SQLSetEnvAttr() sets attributes that affects
all connections in an environment.
ODBC specifications for SQLSetEnvAttr()
| ODBC specification level | In X/Open CLI CAE specification? | In ISO CLI specification? |
|---|---|---|
| No | Yes | Yes |
Syntax
SQLRETURN SQLSetEnvAttr (SQLHENV EnvironmentHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength);Function arguments
The following table lists the data type, use, and description for each argument in this function.
| Data type | Argument | Use | Description |
|---|---|---|---|
| SQLHENV | EnvironmentHandle | input | Environment handle. |
| SQLINTEGER | Attribute | input | Environment attribute to set. See Table 3 for the list of attributes and their descriptions. |
| SQLPOINTER | ValuePtr | input | The value for Attribute. |
| SQLINTEGER | StringLength | input | The length of ValuePtr in bytes if the attribute value is a character string. If Attribute does not denote a string, Db2 ODBC ignores StringLength. |
Usage
When set, the attribute value affects all connections in this environment.
The application can obtain
the current attribute value by calling SQLGetEnvAttr().
Table 3 lists the SQLSetEnvAttr() Attribute values.
The values that are shown in bold are default values.
Attribute values
were renamed in ODBC 3.0. For a summary of the Attributes renamed
in ODBC 3.0, refer to "Changes to SQLSetEnvAttr() attributes".
| Attribute | Contents |
|---|---|
| SQL_ATTR_ODBC_VERSION | A 32-bit integer that determines whether
certain functionality exhibits ODBC 2.0 behavior or ODBC 3.0 behavior.
This value cannot be changed while any connection handles are allocated.
The following values are used to set the value of this attribute:
|
| SQL_ATTR_INFO_ACCTSTR | A null-terminated character string used to identify the client accounting string
to the host database. The length of the attribute value must not exceed 255 characters. Some servers might not be able to handle the entire length of the value provided and might truncate it. If truncation occurs, users will not see any truncation warnings. To reset this attribute, specify this attribute with a zero length. This attribute is ignored if MVSATTACHTYPE=CAF is specified in the initialization file, the application created a Db2 thread using CAF before invoking Db2 ODBC, or the application is a stored procedure. |
| SQL_ATTR_INFO_APPLNAME | A null-terminated character string used to identify the client accounting string
to the host database. The length of the attribute value must not exceed 255 characters. Some servers might not be able to handle the entire length of the value provided and might truncate it. If truncation occurs, users will not see any truncation warnings. To reset this attribute, specify this attribute with a zero length. This attribute is ignored if MVSATTACHTYPE=CAF is specified in the initialization file, the application created a Db2 thread using CAF before invoking Db2 ODBC, or the application is a stored procedure. |
| SQL_ATTR_INFO_USERID | A null-terminated character string used to identify the client accounting string
to the host database. The length of the attribute value must not exceed 128 characters. Some servers might not be able to handle the entire length of the value provided and might truncate it. If truncation occurs, users will not see any truncation warnings. To reset this attribute, specify this attribute with a zero length. This attribute is ignored if MVSATTACHTYPE=CAF is specified in the initialization file, the application created a Db2 thread using CAF before invoking Db2 ODBC, or the application is a stored procedure. |
| SQL_ATTR_INFO_WRKSTNNAME | A null-terminated character string used to identify the client accounting string
to the host database. The length of the attribute value must not exceed 255 characters. Some servers might not be able to handle the entire length of the value provided and might truncate it. If truncation occurs, users will not see any truncation warnings. To reset this attribute, specify this attribute with a zero length. This attribute is ignored if MVSATTACHTYPE=CAF is specified in the initialization file, the application created a Db2 thread using CAF before invoking Db2 ODBC, or the application is a stored procedure. |
| SQL_ATTR_OUTPUT_NTS | A 32-bit integer value which controls the use of
nul-termination in output arguments. The possible values are:
This attribute can only be set when no connection handles are allocated under the environment handle. |
| SQL_ATTR_CONNECTTYPE1 | A 32-bit integer value that specifies whether this
application is to operate in a coordinated or uncoordinated distributed
environment. The possible values are:
This attribute must be set before allocating any connection
handles, otherwise, the 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 IBM® specific: This attribute is an IBM-defined extension. Recommendation: Have 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 |
| SQL_ATTR_MAXCONN2 | A 32-bit integer value corresponding to the number
that maximum concurrent connections that an application wants 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. The value that is in effect when the first connection is established is the value that is used. When the first connection is established, attempts to change this value are rejected. IBM specific: This attribute is an IBM-defined extension. Recommendation: Have 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 because this attribute is not supported in ODBC. |
| Notes:
|
|
Return codes
SQLSetEnvAttr(),
it returns one of the following values: - SQL_SUCCESS
- SQL_INVALID_HANDLE
- SQL_ERROR
Diagnostics
The following table lists each SQLSTATE that this function generates, with a description and explanation for each value.
| SQLSTATE | Description | Explanation |
|---|---|---|
| HY009 | Invalid use of a null pointer. | A null pointer is passed for ValuePtr and the value in *ValuePtr is a string value. |
| 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 is specified in *ValuePtr. |
| HY090 | Invalid string or buffer length. | The StringLength argument is less than 0, but is not SQL_NTS. |
| HY092 | Option type out of range. | The value specified for the argument Attribute is not valid for this version of Db2 ODBC. |
| HYC00 | Driver not capable. | The specified Attribute is not supported by Db2 ODBC. Given specified Attribute value, the value specified for the argument ValuePtr is not supported. |
Example
SQLSetEnvAttr() to set an environment
attribute. Also, see the topic Functions for establishing a distributed
unit-of-work connection. SQLINTEGER output_nts,autocommit;
rc = SQLSetEnvAttr( henv,
SQL_ATTR_OUTPUT_NTS,
( SQLPOINTER ) output_nts,
0
) ;
CHECK_HANDLE( SQL_HANDLE_ENV, henv, rc );