TechNet
Export (0) Print
Expand All

SQLGetConnectAttr

 

System_CAPS_ICON_warning.jpg Warning

SQL Server Native Client (SNAC) is not supported beyond SQL Server 2012. Avoid using SNAC in new development work, and plan to modify applications that currently use it. The Microsoft ODBC Driver for SQL Server provides native connectivity from Windows to Microsoft SQL Server and Microsoft Azure SQL Database.

The SQL Server Native Client ODBC driver defines driver-specific connection attributes. Some of the attributes are available to SQLGetConnectAttr, and the function is used to report their current settings. The values reported for these attributes are not guaranteed until after a connection has been made or the attribute has been set using SQLSetConnectAttr.

This topic lists the read only attributes. For information about the other SQL Server Native Client ODBC driver-specific connection attributes, see SQLSetConnectAttr.

The SQL_COPT_SS_CONNECTION_DEAD attribute reports the state of a connection to a server. The driver queries the network for the current state of the connection.

System_CAPS_ICON_note.jpg Note


The standard ODBC connection attribute SQL_ATTR_CONNECTION_DEAD returns the most recent state of the connection. This might not be the current connection state.

ValueDescription
SQL_CD_TRUEThe connection to the server has been lost.
SQL_CD_FALSEThe connection is open and available for statement processing.

The SQL_COPT_SS_CLIENT_CONNECTION_ID attribute retrieves the client connection ID, which can then be used to locate:

  • Diagnostic information in the XEvents log, when enabled.

  • Connection error information in the connection ring buffer.

  • Diagnostic information in the data access tracing logs, when enabled.

For more information, see Accessing Diagnostic Information in the Extended Events Log.

ValueDescription
SQL_ERRORThe connection failed.
SQL_SUCCESSThe connection succeeded. The client connection ID will be found in the output buffer.

The SQL_COPT_SS_PERF_DATA attribute returns a pointer to a SQLPERF structure containing the current driver performance statistics. SQLGetConnectAttr will return NULL if performance logging is not enabled. The statistics in the SQLPERF structure are not dynamically updated by the driver. Call SQLGetConnectAttr each time the performance statistics need to be refreshed.

ValueDescription
NULLPerformance logging is not enabled.
Any other valueA pointer to a SQLPERF structure.

The SQL_COPT_SS_PERF_QUERY attribute returns TRUE if logging of long running queries is enabled. The request returns FALSE if query logging is not active.

The SQL_COPT_SS_USER_DATA attribute retrieves the user-data pointer. User data is stored in client-owned memory and recorded per connection. If the user-data pointer has not been set, SQL_UD_NOTSET, a NULL pointer, is returned.

ValueDescription
SQL_UD_NOTSETNo user-data pointer is set.
Any other valueA pointer to the user data.

SQLGetConnectAttr can be used to query the value of the new connection attributes SQL_COPT_SS_SERVER_SPN, SQL_COPT_SS_FAILOVER_PARTNER_SPN, SQL_COPT_SS_MUTUALLY_AUTHENTICATED, and SQL_COPT_SS_INTEGRATED_AUTHENTICATION_METHOD. (SQLGetConnectOption can also be used to query these values.)

SQL_COPT_SS_INTEGRATED_AUTHENTICATION_METHOD is only available for open connections that use Windows Authentication.

If SQL_COPT_SS_SERVER_SPN or SQL_COPT_SS_FAILOVER_PARTNER has not been set, the default value (an empty string) is returned.

For more information about SPNs, see Service Principal Names (SPNs) in Client Connections (ODBC).

SQLGetConnectAttr Function
ODBC API Implementation Details
SET QUOTED_IDENTIFIER (Transact-SQL)
SET ANSI_NULLS (Transact-SQL)
SET ANSI_PADDING (Transact-SQL)
SET ANSI_WARNINGS (Transact-SQL)

Community Additions

ADD
Show:
© 2016 Microsoft