SQLSetConnectAttrSQLSetConnectAttr

適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database 是Azure SQL 受控執行個體Azure SQL Managed InstanceYesAzure SQL 受控執行個體Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是平行處理資料倉儲Parallel Data Warehouseyes平行處理資料倉儲Parallel Data Warehouse適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database 是Azure SQL 受控執行個體Azure SQL Managed InstanceYesAzure SQL 受控執行個體Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是平行處理資料倉儲Parallel Data Warehouseyes平行處理資料倉儲Parallel Data Warehouse

SQL ServerSQL Server Native Client ODBC 驅動程式會忽略 SQL_ATTR_CONNECTION_TIMEOUT 的設定。The SQL ServerSQL Server Native Client ODBC driver ignores the setting of SQL_ATTR_CONNECTION_TIMEOUT.

也會忽略 SQL_ATTR_TRANSLATE_LIB;不支援指定其他的翻譯程式庫。SQL_ATTR_TRANSLATE_LIB is also ignored; specifying another translation library is not supported. 若要讓應用程式更容易匯出以使用 SQL ServerSQL Server Microsoft ODBC 驅動程式,任何使用 SQL_ATTR_TRANSLATE_LIB 設定的值將會複製到驅動程式管理員中的緩衝區內外。To allow applications to easily be ported to use a Microsoft ODBC driver for SQL ServerSQL Server, any value set with SQL_ATTR_TRANSLATE_LIB will be copied into and out of a buffer in the Driver Manager.

SQL ServerSQL Server Native Client ODBC 驅動程式會將可重複的讀取交易隔離實作為可序列化。The SQL ServerSQL Server Native Client ODBC driver implements repeatable read transaction isolation as serializable.

SQL Server 2005 (9.x)SQL Server 2005 (9.x) 導入了新交易隔離屬性 SQL_COPT_SS_TXN_ISOLATION 的支援。introduced support for a new transaction isolation attribute, SQL_COPT_SS_TXN_ISOLATION. 將 SQL_COPT_SS_TXN_ISOLATION 設定為 SQL_TXN_SS_SNAPSHOT 代表交易會在快照隔離等級之下發生。Setting SQL_COPT_SS_TXN_ISOLATION to SQL_TXN_SS_SNAPSHOT indicates that the transaction will take place under the snapshot isolation level.

注意

SQL_ATTR_TXN_ISOLATION 可用來設定 SQL_TXN_SS_SNAPSHOT 以外的所有其他隔離等級。SQL_ATTR_TXN_ISOLATION can be used to set all other isolation levels except for SQL_TXN_SS_SNAPSHOT. 如果您想要使用快照集隔離,就必須透過 SQL_COPT_SS_TXN_ISOLATION 設定 SQL_TXN_SS_SNAPSHOT。If you want to use snapshot isolation, you must set SQL_TXN_SS_SNAPSHOT through SQL_COPT_SS_TXN_ISOLATION. 不過,您可以使用 SQL_ATTR_TXN_ISOLATION 或 SQL_COPT_SS_TXN_ISOLATION 來擷取隔離等級。However, you can retrieve the isolation level by using either SQL_ATTR_TXN_ISOLATION or SQL_COPT_SS_TXN_ISOLATION.

將 ODBC 陳述式屬性升級至連接屬性可能會產生非預期的後果。Promoting ODBC statement attributes to connection attributes can have unintended consequences. 您可以將要求伺服器資料指標以進行結果集處理的陳述式屬性升級至連接。Statement attributes that request server cursors for result set processing can be promoted to the connection. 例如,如果您將 ODBC 陳述式屬性 SQL_ATTR_CONCURRENCY 設定為比預設值 SQL_CONCUR_READ_ONLY 更具限制性的值,就會引導驅動程式針對在連接時送出的所有陳述式使用動態資料指標。For example, setting the ODBC statement attribute SQL_ATTR_CONCURRENCY to a value more restrictive than the default SQL_CONCUR_READ_ONLY directs the driver to use dynamic cursors for all statements submitted on the connection. 針對連接的陳述式執行 ODBC 目錄函數會傳回 SQL_SUCCESS_WITH_INFO 以及一個診斷記錄,表示資料指標行為已經變更成唯讀。Executing an ODBC catalog function on a statement on the connection returns SQL_SUCCESS_WITH_INFO and a diagnostic record indicating that the cursor behavior has been changed to read-only. 嘗試執行包含相同連接之 COMPUTE 子句的 Transact-SQL SELECT 陳述式會失敗。Attempting to execute a Transact-SQL SELECT statement containing a COMPUTE clause on the same connection fails.

SQL ServerSQL Server Native Client ODBC 驅動程式會針對 sqlncli.h 中定義的 ODBC 連接屬性支援一些驅動程式特有的延伸模組。The SQL ServerSQL Server Native Client ODBC driver supports a number of driver-specific extensions to ODBC connection attributes defined in sqlncli.h. SQL ServerSQL Server Native Client ODBC 驅動程式可能會要求在連接之前設定此屬性,否則如果已經設定,驅動程式可能會忽略此屬性。The SQL ServerSQL Server Native Client ODBC driver may require that the attribute be set prior to connection, or it may ignore the attribute if it is already set. 下表將列出各項限制。The following table lists restrictions.

SQL Server 屬性SQL Server attribute 在連接至伺服器之前或之後設定Set before or after connection to server
SQL_COPT_SS_ANSI_NPWSQL_COPT_SS_ANSI_NPW 之前Before
SQL_COPT_SS_APPLICATION_INTENTSQL_COPT_SS_APPLICATION_INTENT 之前Before
SQL_COPT_SS_ATTACHDBFILENAMESQL_COPT_SS_ATTACHDBFILENAME 之前Before
SQL_COPT_SS_BCPSQL_COPT_SS_BCP 之前Before
SQL_COPT_SS_BROWSE_CONNECTSQL_COPT_SS_BROWSE_CONNECT 之前Before
SQL_COPT_SS_BROWSE_SERVERSQL_COPT_SS_BROWSE_SERVER 之前Before
SQL_COPT_SS_CONCAT_NULLSQL_COPT_SS_CONCAT_NULL 之前Before
SQL_COPT_SS_CONNECTION_DEADSQL_COPT_SS_CONNECTION_DEAD AfterAfter
SQL_COPT_SS_ENCRYPTSQL_COPT_SS_ENCRYPT 之前Before
SQL_COPT_SS_ENLIST_IN_DTCSQL_COPT_SS_ENLIST_IN_DTC AfterAfter
SQL_COPT_SS_ENLIST_IN_XASQL_COPT_SS_ENLIST_IN_XA AfterAfter
SQL_COPT_SS_FALLBACK_CONNECTSQL_COPT_SS_FALLBACK_CONNECT 之前Before
SQL_COPT_SS_FAILOVER_PARTNERSQL_COPT_SS_FAILOVER_PARTNER 之前Before
SQL_COPT_SS_INTEGRATED_SECURITYSQL_COPT_SS_INTEGRATED_SECURITY 之前Before
SQL_COPT_SS_MARS_ENABLEDSQL_COPT_SS_MARS_ENABLED 之前Before
SQL_COPT_SS_MULTISUBNET_FAILOVERSQL_COPT_SS_MULTISUBNET_FAILOVER 之前Before
SQL_COPT_SS_OLDPWDSQL_COPT_SS_OLDPWD 之前Before
SQL_COPT_SS_PERF_DATASQL_COPT_SS_PERF_DATA AfterAfter
SQL_COPT_SS_PERF_DATA_LOGSQL_COPT_SS_PERF_DATA_LOG AfterAfter
SQL_COPT_SS_PERF_DATA_LOG_NOWSQL_COPT_SS_PERF_DATA_LOG_NOW AfterAfter
SQL_COPT_SS_PERF_QUERYSQL_COPT_SS_PERF_QUERY AfterAfter
SQL_COPT_SS_PERF_QUERY_INTERVALSQL_COPT_SS_PERF_QUERY_INTERVAL AfterAfter
SQL_COPT_SS_PERF_QUERY_LOGSQL_COPT_SS_PERF_QUERY_LOG AfterAfter
SQL_COPT_SS_PRESERVE_CURSORSSQL_COPT_SS_PRESERVE_CURSORS 之前Before
SQL_COPT_SS_QUOTED_IDENTSQL_COPT_SS_QUOTED_IDENT Either
SQL_COPT_SS_TRANSLATESQL_COPT_SS_TRANSLATE Either
SQL_COPT_SS_TRUST_SERVER_CERTIFICATESQL_COPT_SS_TRUST_SERVER_CERTIFICATE 之前Before
SQL_COPT_SS_TXN_ISOLATIONSQL_COPT_SS_TXN_ISOLATION Either
SQL_COPT_SS_USE_PROC_FOR_PREPSQL_COPT_SS_USE_PROC_FOR_PREP Either
SQL_COPT_SS_USER_DATASQL_COPT_SS_USER_DATA Either
SQL_COPT_SS_WARN_ON_CP_ERRORSQL_COPT_SS_WARN_ON_CP_ERROR 之前Before

針對相同工作階段、資料庫或 Transact-SQLTransact-SQL 狀態使用預先連接屬性與對等 SQL ServerSQL Server 命令,可能會產生非預期的行為。Using a pre-connection attribute and the equivalent Transact-SQLTransact-SQL command for the same session, database, or SQL ServerSQL Server state can produce unexpected behavior. 例如,For example,

SQLSetConnectAttr(SQL_COPT_SS_QUOTED_IDENT, SQL_QI_ON) // turn ON via attribute  
SQLDriverConnect(...);  
SQLExecDirect("SET QUOTED_IDENTIFIER OFF") // turn OFF via Transact-SQL  
SQLSetConnectAttr(SQL_ATTR_CURRENT_CATALOG, ...) // restores to pre-connect attribute value  

SQL_COPT_SS_ANSI_NPWSQL_COPT_SS_ANSI_NPW

SQL_COPT_SS_ANSI_NPW 會在比較與串連、字元資料類型填補和警告中啟用或停用 NULL ISO 處理的使用方式。SQL_COPT_SS_ANSI_NPW enables or disables the use of ISO handling of NULL in comparisons and concatenation, character data type padding, and warnings. 如需詳細資訊,請參閱 SET ANSI_NULLS、SET ANSI_PADDING、SET ANSI_WARNINGS 和 SET CONCAT_NULL_YIELDS_NULL。For more information, see SET ANSI_NULLS, SET ANSI_PADDING, SET ANSI_WARNINGS, and SET CONCAT_NULL_YIELDS_NULL.

Value 描述Description
SQL_AD_ONSQL_AD_ON 預設值。Default. 連接會使用 ANSI 預設行為來處理 NULL 比較、填補、警告和 NULL 串連。The connection uses ANSI default behavior for handling NULL comparisons, padding, warnings, and NULL concatenations.
SQL_AD_OFFSQL_AD_OFF 連接會針對 NULL、字元資料類型填補和警告使用 SQL ServerSQL Server 定義的處理方式。The connection uses SQL ServerSQL Server-defined handling of NULL, character data type padding, and warnings.

如果您使用連接共用,SQL_COPT_SS_ANSI_NPW 應該在連接字串中設定,而不是在 SQLSetConnectAttr 中設定。If you use connection pooling, SQL_COPT_SS_ANSI_NPW should be set in the connection string, rather than with SQLSetConnectAttr. 已經建立連接之後,在使用連接共用時,任何嘗試變更此屬性的行為將會以無訊息的方式發生失敗。After a connection has been made, any attempt to change this attribute will fail silently when connection pooling is used.

SQL_COPT_SS_APPLICATION_INTENTSQL_COPT_SS_APPLICATION_INTENT

宣告連接到伺服器時的應用程式工作負載類型。Declares the application workload type when connecting to a server. 可能的值為 ReadonlyReadWritePossible values are Readonly and ReadWrite. 例如:For example:

SQLSetConnectAttr(hdbc, SQL_COPT_SS_APPLICATION_INTENT, TEXT("Readonly"), SQL_NTS)  

預設值為 ReadWriteThe default is ReadWrite. 如需有關 SQL ServerSQL Server Native Client 的 ag 支援的詳細資訊 Always On 可用性群組Always On availability groups ,請參閱 SQL Server Native Client 高可用性和嚴重損壞修復的支援For more information about SQL ServerSQL Server Native Client's support for Always On 可用性群組Always On availability groups AGs, see SQL Server Native Client Support for High Availability, Disaster Recovery.

SQL_COPT_SS_ATTACHDBFILENAMESQL_COPT_SS_ATTACHDBFILENAME

SQL_COPT_SS_ATTACHDBFILENAME 會指定可附加資料庫的主要檔案名稱。SQL_COPT_SS_ATTACHDBFILENAME specifies the name of the primary file of an attachable database. 此資料庫會附加,而且變成連接的預設資料庫。This database is attached and becomes the default database for the connection. 若要使用 SQL_COPT_SS_ATTACHDBFILENAME 您必須指定資料庫的名稱,做為連接屬性的值 SQL_ATTR_CURRENT_CATALOG 或在 SQLDriverConnect的 database = 參數中。To use SQL_COPT_SS_ATTACHDBFILENAME you must specify the name of the database as the value of the connection attribute SQL_ATTR_CURRENT_CATALOG or in the DATABASE = parameter of a SQLDriverConnect. 如果該資料庫先前已附加,SQL ServerSQL Server 將不會重新附加它。If the database was previously attached, SQL ServerSQL Server will not reattach it.

Value 描述Description
字元字串的 SQLPOINTERSQLPOINTER to a character string 此字串包含要附加之資料庫的主要檔案名稱。The string contains the name of the primary file for the database to attach. 請加入檔案的完整路徑名稱。Include the full path name of the file.

SQL_COPT_SS_BCPSQL_COPT_SS_BCP

SQL_COPT_SS_BCP 會針對連接啟用大量複製函數。SQL_COPT_SS_BCP enables bulk copy functions on a connection. 如需詳細資訊,請參閱 大量複製函數For more information, see Bulk Copy Functions.

Value 描述Description
SQL_BCP_OFFSQL_BCP_OFF 預設值。Default. 無法針對連接使用大量複製函數。Bulk copy functions are not available on the connection.
SQL_BCP_ONSQL_BCP_ON 可以針對連接使用大量複製函數。Bulk copy functions are available on the connection.

SQL_COPT_SS_BROWSE_CONNECTSQL_COPT_SS_BROWSE_CONNECT

這個屬性是用來自訂 SQLBrowseConnect所傳回的結果集。This attribute is used to customize the result set returned by SQLBrowseConnect. SQL_COPT_SS_BROWSE_CONNECT 會啟用或停用從 SQL ServerSQL Server 列舉執行個體傳回其他資訊的作業。SQL_COPT_SS_BROWSE_CONNECT enables or disables the return of additional information from an enumerated instance of SQL ServerSQL Server. 這可能會包括伺服器是否為叢集、不同執行個體的名稱,以及版本號碼等資訊。This can include information such as whether the server is a cluster, names of different instances, and the version number.

Value 描述Description
SQL_MORE_INFO_NOSQL_MORE_INFO_NO 預設值。Default. 傳回伺服器的清單。Returns a list of servers.
SQL_MORE_INFO_YESSQL_MORE_INFO_YES SQLBrowseConnect 會傳回伺服器屬性的擴充字串。SQLBrowseConnect returns an extended string of server properties.

SQL_COPT_SS_BROWSE_SERVERSQL_COPT_SS_BROWSE_SERVER

這個屬性是用來自訂 SQLBrowseConnect 所傳回的結果集。This attribute is used to customize the result set returned by SQLBrowseConnect. SQL_COPT_SS_BROWSE_SERVER 指定 SQLBrowseConnect 傳回信息的伺服器名稱。SQL_COPT_SS_BROWSE_SERVER specifies the server name for which SQLBrowseConnect returns the information.

Value 描述Description
computernamecomputername SQLBrowseConnect 會傳回 SQL ServerSQL Server 指定電腦上的實例清單。SQLBrowseConnect returns a list of instances of SQL ServerSQL Server on the specified computer. 雙反斜線 (\ \) 不應該用於伺服器名稱 (例如,而不是使用 \ \MyServer,則應該使用) 來取代 MyServer。Double backslashes (\\) should not be used for the server name (for example, instead of \\MyServer, MyServer should be used).
NULLNULL 預設值。Default. SQLBrowseConnect 會傳回網域中所有伺服器的資訊。SQLBrowseConnect returns information for all servers in the domain.

SQL_COPT_SS_CONCAT_NULLSQL_COPT_SS_CONCAT_NULL

SQL_COPT_SS_CONCAT_NULL 會在串連字元時啟用或停用 NULL ISO 處理的使用方式。SQL_COPT_SS_CONCAT_NULL enables or disables the use of ISO handling of NULL when concatenating strings. 如需詳細資訊,請參閱 SET CONCAT_NULL_YIELDS_NULL。For more information, see SET CONCAT_NULL_YIELDS_NULL.

Value 描述Description
SQL_CN_ONSQL_CN_ON 預設值。Default. 連接會在串連字串時使用 ISO 預設行為來處理 NULL 值。The connection uses ISO default behavior for handling NULL values when concatenating strings.
SQL_CN_OFFSQL_CN_OFF 連接會在串連字串時使用 SQL ServerSQL Server 定義的行為來處理 NULL 值。The connection uses SQL ServerSQL Server-defined behavior for handling NULL values when concatenating strings.

SQL_COPT_SS_ENCRYPTSQL_COPT_SS_ENCRYPT

控制連接的加密。Controls encryption for a connection.

加密會使用伺服器上的憑證。Encryption uses the certificate on the server. 除非連接屬性 SQL_COPT_SS_TRUST_SERVER_CERTIFICATE 設定為 SQL_TRUST_SERVER_CERTIFICATE_YES 或連接字串包含 "TrustServerCertificate=yes",否則這個憑證必須經過憑證授權單位驗證。This must be verified by a certificate authority, unless the connection attribute SQL_COPT_SS_TRUST_SERVER_CERTIFICATE is set to SQL_TRUST_SERVER_CERTIFICATE_YES or the connection string contains "TrustServerCertificate=yes". 如果其中一項條件成立,當伺服器上沒有任何憑證時,伺服器所產生並簽署的憑證就可用來加密連接。If either of these conditions is true, a certificate generated and signed by the server can be used to encrypt the connection if no certificate is on the server.

Value 描述Description
SQL_EN_ONSQL_EN_ON 連接將會加密。The connection will be encrypted.
SQL_EN_OFFSQL_EN_OFF 連接將不會加密。The connection will not be encrypted. 此為預設值。This is the default.

SQL_COPT_SS_ENLIST_IN_DTCSQL_COPT_SS_ENLIST_IN_DTC

用戶端會呼叫 Microsoft Distributed Transaction Coordinator (MS DTC) OLE DB ITransactionDispenser:: BeginTransaction 方法來開始 MS DTC 交易,並建立代表交易的 MS DTC 交易對象。The client calls the Microsoft Distributed Transaction Coordinator (MS DTC) OLE DB ITransactionDispenser::BeginTransaction method to begin an MS DTC transaction and create an MS DTC transaction object that represents the transaction. 然後,應用程式會使用 SQL_COPT_SS_ENLIST_IN_DTC 選項來呼叫 SQLSetConnectAttr ,以便將交易對象與 ODBC 連接產生關聯。The application then calls SQLSetConnectAttr with the SQL_COPT_SS_ENLIST_IN_DTC option to associate the transaction object with the ODBC connection. 所有相關的資料庫活動都將在 MS DTC 交易的保護底下進行。All related database activity will be performed under the protection of the MS DTC transaction. 應用程式會使用 SQL_DTC_DONE 來呼叫 SQLSetConnectAttr ,以結束連接的 DTC 關聯。The application calls SQLSetConnectAttr with SQL_DTC_DONE to end the connection's DTC association.

Value 描述Description
DTC object*DTC object* 指定要匯出至 SQL ServerSQL Server 之交易的 MS DTC OLE 交易物件。The MS DTC OLE transaction object that specifies the transaction to export to SQL ServerSQL Server.
SQL_DTC_DONESQL_DTC_DONE 分隔 DTC 交易的結尾。Delimits the end of a DTC transaction.

SQL_COPT_SS_ENLIST_IN_XASQL_COPT_SS_ENLIST_IN_XA

若要使用 XA 相容的交易處理器來開始 XA 交易 (TP) ,用戶端會呼叫 Open Group tx_begin 函數。To begin an XA transaction with an XA-compliant Transaction Processor (TP), the client calls the Open Group tx_begin function. 然後,應用程式會使用 SQL_COPT_SS_ENLIST_IN_XA 參數 TRUE 來呼叫 SQLSetConnectAttr ,以將 XA 交易與 ODBC 連接產生關聯。The application then calls SQLSetConnectAttr with a SQL_COPT_SS_ENLIST_IN_XA parameter of TRUE to associate the XA transaction with the ODBC connection. 所有相關的資料庫活動都將在 XA 交易的保護底下進行。All related database activity will be performed under the protection of the XA transaction. 若要結束與 ODBC 連接的 XA 關聯,用戶端必須使用 SQL_COPT_SS_ENLIST_IN_XA 參數 FALSE 來呼叫 SQLSetConnectAttrTo end an XA association with an ODBC connection, the client must call SQLSetConnectAttr with a SQL_COPT_SS_ENLIST_IN_XA parameter of FALSE. 如需詳細資訊,請參閱 Microsoft 分散式交易協調器文件集。For more information, see the Microsoft Distributed Transaction Coordinator documentation.

SQL_COPT_SS_FALLBACK_CONNECTSQL_COPT_SS_FALLBACK_CONNECT

已不再支援這個屬性。This attribute is no longer supported.

SQL_COPT_SS_FAILOVER_PARTNERSQL_COPT_SS_FAILOVER_PARTNER

用於指定或擷取在 SQL ServerSQL Server 中鏡像資料庫所使用之容錯移轉夥伴的名稱,而且這是以 null 結尾的字元字串,必須在一開始建立 SQL ServerSQL Server 的連接前設定。Used to specify or retrieve the name of the failover partner used for database mirroring in SQL ServerSQL Server, and it is a null terminated character string which must be set before the connection to SQL ServerSQL Server is initially made.

進行連接之後,應用程式可以使用 SQLGetConnectAttr 來查詢此屬性,以判斷容錯移轉夥伴的身分識別。After making the connection, the application can query this attribute using SQLGetConnectAttr to determine the identity of the failover partner. 如果主要伺服器沒有容錯移轉夥伴,此屬性將會傳回空字串。If the primary server has no failover partner this property will return an empty string. 這可讓智慧型應用程式快取最近決定的備份伺服器,但是此類應用程式應該會注意到此資訊只會在第一次建立 (如果共用,則重設) 連接時更新,而且在長期連接後會變成過期。This allows a smart application to cache the most recently determined backup server, but such applications should be aware that the information is only updated when the connection is first established, or reset, if pooled, and can become out of date for long term connections.

如需詳細資訊,請參閱使用資料庫鏡像For more information, see Using Database Mirroring.

SQL_COPT_SS_INTEGRATED_SECURITYSQL_COPT_SS_INTEGRATED_SECURITY

SQL_COPT_SS_INTEGRATED_SECURITY 會針對伺服器登入的存取驗證強制使用 Windows 驗證。SQL_COPT_SS_INTEGRATED_SECURITY forces use of Windows Authentication for access validation on server login. 使用 Windows 驗證時,驅動程式會忽略 SQLConnectSQLDriverConnectSQLBrowseConnect 處理過程中所提供的使用者識別碼和密碼值。When Windows Authentication is used, the driver ignores user identifier and password values provided as part of SQLConnect, SQLDriverConnect, or SQLBrowseConnect processing.

Value 描述Description
SQL_IS_OFFSQL_IS_OFF 預設值。Default. 在登入時使用 SQL ServerSQL Server 驗證來驗證使用者識別碼和密碼。SQL ServerSQL Server Authentication is used to validate user identifier and password on login.
SQL_IS_ONSQL_IS_ON 使用 Windows 驗證模式來驗證使用者對 SQL ServerSQL Server 的存取權限。Windows Authentication Mode is used to validate a user's access rights to the SQL ServerSQL Server.

SQL_COPT_SS_MARS_ENABLEDSQL_COPT_SS_MARS_ENABLED

這個屬性會啟用或停用 Multiple Active Result Sets (MARS)。This attribute enables or disables Multiple Active Result Sets (MARS). 根據預設,MARS 已停用。By default, MARS is disabled. 您應該在建立 SQL ServerSQL Server 的連接之前設定這個屬性。This attribute should be set before making a connection to SQL ServerSQL Server. 開啟連接 SQL ServerSQL Server 之後,MARS 將會在連接期間維持啟用或停用狀態。Once the connection SQL ServerSQL Server is opened, MARS will remain enabled or disabled for the life of the connection.

Value 描述Description
SQL_MARS_ENABLED_NOSQL_MARS_ENABLED_NO 預設值。Default. 停用 Multiple Active Result Sets (MARS)。Multiple Active Result Sets (MARS) is disabled.
SQL_MARS_ENABLED_YESSQL_MARS_ENABLED_YES 啟用 MARS。MARS is enabled.

如需 MARS 的詳細資訊,請參閱 使用 (mars)的 Multiple Active Result Sets For more information about MARS, see Using Multiple Active Result Sets (MARS).

SQL_COPT_SS_MULTISUBNET_FAILOVERSQL_COPT_SS_MULTISUBNET_FAILOVER

如果您的應用程式要連接到不同子網路上的 Always On 可用性群組Always On availability groups 可用性群組 (AG),則這個連接屬性會設定 SQL ServerSQL Server Native Client 來提供目前使用中伺服器的更快速偵測與連接。If your application is connecting to a Always On 可用性群組Always On availability groups availability group (AG) on different subnets, this connection property configures SQL ServerSQL Server Native Client to provide faster detection of and connection to the (currently) active server. 例如:For example:

SQLSetConnectAttr(hdbc, SQL_COPT_SS_MULTISUBNET_FAILOVER, SQL_IS_ON, SQL_IS_INTEGER)  

如需有關 SQL ServerSQL Server Native Client 的 ag 支援的詳細資訊 Always On 可用性群組Always On availability groups ,請參閱 SQL Server Native Client 高可用性和嚴重損壞修復的支援For more information about SQL ServerSQL Server Native Client's support for Always On 可用性群組Always On availability groups AGs, see SQL Server Native Client Support for High Availability, Disaster Recovery.

Value 描述Description
SQL_IS_ONSQL_IS_ON SQL ServerSQL Server Native Client 會在發生容錯移轉時提供更快速的重新連接。Native Client provides faster reconnection if there is a failover.
SQL_IS_OFFSQL_IS_OFF SQL ServerSQL Server Native Client 不會在發生容錯移轉時提供更快速的重新連接。Native Client will not provide faster reconnection if there is a failover.

SQL_COPT_SS_OLDPWDSQL_COPT_SS_OLDPWD

SQL Server 驗證的密碼逾期是在 SQL Server 2005 (9.x)SQL Server 2005 (9.x) 中導入的。Password expiration for SQL Server Authentication was introduced in SQL Server 2005 (9.x)SQL Server 2005 (9.x). 目前加入了 SQL_COPT_SS_OLDPWD 屬性,可讓用戶端同時提供舊的和新的密碼進行連接。The SQL_COPT_SS_OLDPWD attribute has been added to allow the client to provide both the old and the new password for the connection. 設定這個屬性之後,提供者將不會針對第一次連接或後續連接使用連接集區,因為連接字串將會包含已經變更的「舊密碼」。When this property is set, the provider will not use the connection pool for the first connection or for subsequent connections, since the connection string will contain the "old password" which has now changed.

如需詳細資訊,請參閱 以程式設計方式變更密碼For more information, see Changing Passwords Programmatically.

Value 描述Description
SQL_COPT_SS_OLD_PASSWORDSQL_COPT_SS_OLD_PASSWORD 包含舊密碼之字元字串的 SQLPOINTER。SQLPOINTER to a character string containing the old password. 這個值是唯寫的,而且必須在連接至伺服器之前設定。This value is write-only, and must be set before connection to the server.

SQL_COPT_SS_PERF_DATASQL_COPT_SS_PERF_DATA

SQL_COPT_SS_PERF_DATA 會啟動或停止效能資料記錄。SQL_COPT_SS_PERF_DATA starts or stops performance data logging. 您必須在啟動資料記錄之前設定資料記錄檔名稱。The data log file name must be set prior to starting data logging. 請參閱下面的 SQL_COPT_SS_PERF_DATA_LOG。See SQL_COPT_SS_PERF_DATA_LOG below.

Value 描述Description
SQL_PERF_STARTSQL_PERF_START 開始讓驅動程式進行效能資料取樣。Starts the driver sampling performance data.
SQL_PERF_STOPSQL_PERF_STOP 停止讓計數器進行效能資料取樣。Stops the counters from sampling performance data.

如需詳細資訊,請參閱 SQLGetConnectAttrFor more information, see SQLGetConnectAttr.

SQL_COPT_SS_PERF_DATA_LOGSQL_COPT_SS_PERF_DATA_LOG

SQL_COPT_SS_PERF_DATA_LOG 會指派用來記錄效能資料之記錄檔的名稱。SQL_COPT_SS_PERF_DATA_LOG assigns the name of the log file used to record performance data. 此記錄檔名稱是以 Null 結束的 ANSI 或 Unicode 字串,端視應用程式編譯方式而定。The log file name is an ANSI or Unicode, null-terminated string depending upon application compilation. 應 SQL_NTS StringLength 引數。The StringLength argument should be SQL_NTS.

SQL_COPT_SS_PERF_DATA_LOG_NOWSQL_COPT_SS_PERF_DATA_LOG_NOW

SQL_COPT_SS_PERF_DATA_LOG_NOW 會指示驅動程式將統計資料記錄項目寫入磁碟。SQL_COPT_SS_PERF_DATA_LOG_NOW instructs the driver to write a statistics log entry to disk. 應 SQL_NTS StringLength 引數。The StringLength argument should be SQL_NTS.

SQL_COPT_SS_PERF_QUERYSQL_COPT_SS_PERF_QUERY

SQL_COPT_SS_PERF_QUERY 會啟動或停止長時間執行查詢的記錄。SQL_COPT_SS_PERF_QUERY starts or stops logging for long running queries. 您必須在啟動記錄之前提供查詢記錄檔名稱。The query log file name must be supplied prior to starting logging. 應用程式可以透過設定記錄的間隔,定義「長時間執行」。The application can define "long running" by setting the interval for logging.

Value 描述Description
SQL_PERF_STARTSQL_PERF_START 啟動長時間執行查詢記錄。Starts long running query logging.
SQL_PERF_STOPSQL_PERF_STOP 停止長時間執行查詢的記錄。Stops logging of long running queries.

如需詳細資訊,請參閱 SQLGetConnectAttrFor more information, see SQLGetConnectAttr.

SQL_COPT_SS_PERF_QUERY_INTERVALSQL_COPT_SS_PERF_QUERY_INTERVAL

SQL_COPT_SS_PERF_QUERY_INTERVAL 會設定查詢記錄臨界值 (以毫秒為單位)。SQL_COPT_SS_PERF_QUERY_INTERVAL sets the query logging threshold in milliseconds. 沒有在此臨界值內解決的查詢就會記錄在長時間執行查詢記錄檔中。Queries that do not resolve within the threshold are recorded in the long running query log file. 查詢臨界值沒有任何上限。There is no upper limit on the query threshold. 如果查詢臨界值為零,就會導致系統記錄所有查詢。A query threshold value of zero causes logging of all queries.

SQL_COPT_SS_PERF_QUERY_LOGSQL_COPT_SS_PERF_QUERY_LOG

SQL_COPT_SS_PERF_QUERY_LOG 會指派用於記錄長時間執行查詢資料之記錄檔的名稱。SQL_COPT_SS_PERF_QUERY_LOG assigns the name of a log file for recording long running query data. 此記錄檔名稱是以 Null 結束的 ANSI 或 Unicode 字串,端視應用程式編譯方式而定。The log file name is an ANSI or Unicode, null-terminated string depending upon application compilation. StringLength 引數應該是 SQL_NTS 或字串的長度(以位元組為單位)。The StringLength argument should be SQL_NTS or the length of the string in bytes.

SQL_COPT_SS_PRESERVE_CURSORSSQL_COPT_SS_PRESERVE_CURSORS

這個屬性可讓您查詢並設定在認可/回復交易時,連接是否要保留資料指標。This attribute allows you to query and set whether or not the connection will preserve the cursor(s) when you commit/rollback a transaction. 此設定為 SQL_PC_ON 或 SQL_PC_OFF。The setting is either SQL_PC_ON or SQL_PC_OFF. 預設值為 SQL_PC_OFF。The default value is SQL_PC_OFF. 當您呼叫 SQLEndTran (或 SQLTransact) 時,此設定會控制驅動程式是否會關閉游標 (s) 。This setting controls whether or not the driver will close the cursor(s) for you when you call SQLEndTran (or SQLTransact).

Value 描述Description
SQL_PC_OFFSQL_PC_OFF 預設值。Default. 使用 SQLEndTran 認可或回復交易時,會關閉資料指標。Cursors are closed when transaction is committed or rolled back using SQLEndTran.
SQL_PC_ONSQL_PC_ON 使用 SQLEndTran 認可或回復交易時,不會關閉資料指標,但在非同步模式中使用靜態或索引鍵集資料指標時除外。Cursors are not closed when transaction is committed or rolled back using SQLEndTran, except when using a static or keyset cursor in asynchronous mode. 如果您在資料指標的母體未完成時發出了回復,就會關閉資料指標。If a rollback is issued while the population of the cursor is not complete, the cursor is closed.

SQL_COPT_SS_QUOTED_IDENTSQL_COPT_SS_QUOTED_IDENT

SQL_COPT_SS_QUOTED_IDENT 允許在連接時送出的 ODBC 和 Transact-SQL 陳述式中使用引號識別碼。SQL_COPT_SS_QUOTED_IDENT allows quoted identifiers in ODBC and Transact-SQL statements submitted on the connection. 透過提供引號識別碼,SQL ServerSQL Server Native Client ODBC 驅動程式會允許其他無效的物件名稱,例如 "My Table" (識別碼包含空格字元)。By supplying quoted identifiers, the SQL ServerSQL Server Native Client ODBC driver allows otherwise invalid object names such as "My Table", which contains a space character in the identifier. 如需詳細資訊,請參閱 SET QUOTED_IDENTIFIER。For more information, see SET QUOTED_IDENTIFIER.

Value 描述Description
SQL_QI_OFFSQL_QI_OFF SQL ServerSQL Server 連接不允許在送出的 Transact-SQLTransact-SQL 中使用引號識別碼。The SQL ServerSQL Server connection does not allow quoted identifiers in submitted Transact-SQLTransact-SQL.
SQL_QI_ONSQL_QI_ON 預設值。Default. 連接允許在送出的 Transact-SQLTransact-SQL 中使用引號識別碼。The connection allows quoted identifiers in submitted Transact-SQLTransact-SQL.

SQL_COPT_SS_TRANSLATESQL_COPT_SS_TRANSLATE

SQL_COPT_SS_TRANSLATE 會在交換 MBCS 資料時,讓驅動程式在用戶端與伺服器字碼頁之間轉譯字元。SQL_COPT_SS_TRANSLATE causes the driver to translate characters between the client and server code pages as MBCS data is exchanged. 屬性只會影響儲存在 SQL ServerSQL Server charVarchartext 資料行中的資料。The attribute affects only data stored in SQL ServerSQL Serverchar, varchar, and text columns.

Value 描述Description
SQL_XL_OFFSQL_XL_OFF 此驅動程式不會在用戶端與伺服器之間交換的字元資料中,將字元從某個字碼頁轉譯至另一個字碼頁。The driver does not translate characters from one code page to another in character data exchanged between the client and the server.
SQL_XL_ONSQL_XL_ON 預設值。Default. 此驅動程式會在用戶端與伺服器之間交換的字元資料中,將字元從某個字碼頁轉譯至另一個字碼頁。The driver translates characters from one code page to another in character data exchanged between the client and the server. 此驅動程式會自動設定字元轉譯,並判斷伺服器所安裝的字碼頁以及用戶端使用中的字碼頁。The driver automatically configures the character translation, determining the code page installed on the server and that in use by the client.

SQL_COPT_SS_TRUST_SERVER_CERTIFICATESQL_COPT_SS_TRUST_SERVER_CERTIFICATE

SQL_COPT_SS_TRUST_SERVER_CERTIFICATE 會在使用加密時,讓驅動程式啟用或停用憑證驗證。SQL_COPT_SS_TRUST_SERVER_CERTIFICATE causes the driver to enable or disable certificate validation when using encryption. 雖然此屬性是讀取/寫入值,但是在建立連接之後設定此屬性沒有任何作用。This attribute is a read/write value, but setting it after a connection has been established has no effect.

用戶端應用程式可以在開啟連接之後查詢此屬性,以便判斷使用中的實際加密和驗證設定。Client applications can query this property after a connection has been opened to determine the actual encryption and validation settings in use.

Value 描述Description
SQL_TRUST_SERVER_CERTIFICATE_NOSQL_TRUST_SERVER_CERTIFICATE_NO 預設值。Default. 不啟用沒有憑證驗證的加密。Encryption without certificate validation is not enabled.
SQL_TRUST_SERVER_CERTIFICATE_YESSQL_TRUST_SERVER_CERTIFICATE_YES 啟用沒有憑證驗證的加密。Encryption without certificate validation is enabled.

SQL_COPT_SS_TXN_ISOLATIONSQL_COPT_SS_TXN_ISOLATION

SQL_COPT_SS_TXN_ISOLATION 會設定 SQL ServerSQL Server 特有的快照集隔離屬性。SQL_COPT_SS_TXN_ISOLATION sets the SQL ServerSQL Server specific snapshot isolation attribute. 您無法使用 SQL_ATTR_TXN_ISOLATION 來設定快照集隔離,因為此值是 SQL ServerSQL Server 特有的。Snapshot isolation cannot be set using SQL_ATTR_TXN_ISOLATION because the value is SQL ServerSQL Server specific. 不過,您可以使用 SQL_ATTR_TXN_ISOLATION 或 SQL_COPT_SS_TXN_ISOLATION 來擷取此值。However, it can be retrieved using either SQL_ATTR_TXN_ISOLATION or SQL_COPT_SS_TXN_ISOLATION.

Value 描述Description
SQL_TXN_SS_SNAPSHOTSQL_TXN_SS_SNAPSHOT 表示您無法從某個交易看到在其他交易中所產生的變更,而且即使重新查詢,您也無法看見變更。Indicates that from one transaction you cannot see changes made in other transactions and that you cannot see changes even when requerying.

如需快照集隔離的詳細資訊,請參閱 使用快照集隔離For more information about snapshot isolation, see Working with Snapshot Isolation.

SQL_COPT_SS_USE_PROC_FOR_PREPSQL_COPT_SS_USE_PROC_FOR_PREP

已不再支援這個屬性。This attribute is no longer supported.

SQL_COPT_SS_USER_DATASQL_COPT_SS_USER_DATA

SQL_COPT_SS_USER_DATA 會設定使用者資料指標。SQL_COPT_SS_USER_DATA sets the user data pointer. 使用者資料是針對每個連接記錄在用戶端擁有的記憶體中。User data is client-owned memory recorded per connection.

如需詳細資訊,請參閱 SQLGetConnectAttrFor more information, see SQLGetConnectAttr.

SQL_COPT_SS_WARN_ON_CP_ERRORSQL_COPT_SS_WARN_ON_CP_ERROR

這個屬性會決定如果字碼頁轉換期間發生資料遺失,您是否將收到警告。This attribute determines whether you will get a warning if there is a loss of data during a code page conversion. 這個屬性僅適用於來自伺服器的資料。This applies to only data coming from the server.

Value 描述Description
SQL_WARN_YESSQL_WARN_YES 在字碼頁轉換期間發生資料遺失時產生警告。Generate warnings when data loss is encountered during codepage conversion.
SQL_WARN_NOSQL_WARN_NO (預設值) 在字碼頁轉換期間發生資料遺失時不產生警告。(Default) Do not generate warnings when data loss is encountered during codepage conversion.

服務主要名稱 (SPN) 的 SQLSetConnectAttr 支援SQLSetConnectAttr Support for Service Principal Names (SPNs)

SQLSetConnectAttr 可以用來設定新的連接屬性值 SQL_COPT_SS_SERVER_SPN 和 SQL_COPT_SS_FAILOVER_PARTNER_SPN。SQLSetConnectAttr can be used to set the value of the new connection attributes SQL_COPT_SS_SERVER_SPN and SQL_COPT_SS_FAILOVER_PARTNER_SPN. 這些屬性無法在連接已開啟時設定。如果您嘗試在連接已開啟時設定這些屬性,就會傳回錯誤 HY011 並顯示「此時作業無效」訊息These attributes cannot be set when a connection is open; if you attempt to set these attributes when a connection is open, error HY011 is returned with the message "Operation invalid at this time". (的 SQLSetConnectOption 也可以用來設定這些值。 ) (SQLSetConnectOption can also be used to set these values.)

如需 Spn 的詳細資訊,請參閱 (ODBC)之用戶端連接中的服務主體名稱 (spn) For more information about SPNs, see Service Principal Names (SPNs) in Client Connections (ODBC).

SQL_COPT_SS_CONNECTION_DEADSQL_COPT_SS_CONNECTION_DEAD

這是唯讀的屬性。This is a read-only attribute.

如需 SQL_COPT_SS_CONNECTION_DEAD 的詳細資訊,請參閱 SQLGetConnectAttr連接至資料來源 (ODBC)For more information about SQL_COPT_SS_CONNECTION_DEAD, see SQLGetConnectAttr and Connecting to a Data Source (ODBC).

範例Example

這則範例會記錄效能資料。This example logs performance data.

SQLPERF*     pSQLPERF;  
SQLINTEGER   nValue;  
  
// See if you are already logging. SQLPERF* will be NULL if not.  
SQLGetConnectAttr(hDbc, SQL_COPT_SS_PERF_DATA, &pSQLPERF,  
    sizeof(SQLPERF*), &nValue);  
  
if (pSQLPERF == NULL)  
    {  
    // Set the performance log file name.  
    SQLSetConnectAttr(hDbc, SQL_COPT_SS_PERF_DATA_LOG,  
        (SQLPOINTER) "\\My LogDirectory\\MyServerLog.txt", SQL_NTS);  
  
    // Start logging...  
    SQLSetConnectAttr(hDbc, SQL_COPT_SS_PERF_DATA,  
        (SQLPOINTER) SQL_PERF_START, SQL_IS_INTEGER);  
    }  
else  
    {  
    // Take a snapshot now so that your performance statistics are discernible.  
    SQLSetConnectAttr(hDbc, SQL_COPT_SS_PERF_DATA_LOG_NOW, NULL, 0);  
    }  
  
    // ...perform some action...  
  
// ...take a performance data snapshot...  
SQLSetConnectAttr(hDbc, SQL_COPT_SS_PERF_DATA_LOG_NOW, NULL, 0);  
  
    // ...perform more actions...  
  
// ...take another snapshot...  
SQLSetConnectAttr(hDbc, SQL_COPT_SS_PERF_DATA_LOG_NOW, NULL, 0);  
  
// ...and disable logging.  
SQLSetConnectAttr(hDbc, SQL_COPT_SS_PERF_DATA,  
    (SQLPOINTER) SQL_PERF_STOP, SQL_IS_INTEGER);  
  
// Continue on...  

另請參閱See Also

SQLSetConnectAttr 函式 SQLSetConnectAttr Function
ODBC API 的執行詳細資料 ODBC API Implementation Details
大量複製函數 Bulk Copy Functions
SET ANSI_NULLS (Transact-SQL) SET ANSI_NULLS (Transact-SQL)
SET ANSI_PADDING (Transact-SQL) SET ANSI_PADDING (Transact-SQL)
SET ANSI_WARNINGS (Transact-SQL) SET ANSI_WARNINGS (Transact-SQL)
SET CONCAT_NULL_YIELDS_NULL (Transact-SQL) SET CONCAT_NULL_YIELDS_NULL (Transact-SQL)
SET QUOTED_IDENTIFIER (Transact-SQL) SET QUOTED_IDENTIFIER (Transact-SQL)
SQLPrepare 函式 SQLPrepare Function
SQLGetInfoSQLGetInfo