ISO 選項的作用Effects of ISO Options

適用於: 是SQL Server 是Azure SQL Database 是Azure Synapse Analytics (SQL DW) 是平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) yesParallel Data Warehouse

ODBC 標準與 ISO 標準相當接近,而且 ODBC 應用程式應該是來自 ODBC 驅動程式的標準行為。The ODBC standard is closely matched to the ISO standard, and ODBC applications expect standard behavior from an ODBC driver. 為了讓其行為與 ODBC standard 中定義的更緊密地進行比對,SQL ServerSQL Server Native Client ODBC 驅動程式一律會使用所連接之 SQL Server 版本中提供的任何 ISO 選項。To make its behavior conform more closely with that defined in the ODBC standard, the SQL ServerSQL Server Native Client ODBC driver always uses any ISO options available in the version of SQL Server with which it connects.

SQL ServerSQL Server Native Client ODBC 驅動程式連接到 SQL ServerSQL Server的實例時,伺服器會偵測到用戶端正在使用 SQL ServerSQL Server Native Client ODBC 驅動程式,並在上設定數個選項。When the SQL ServerSQL Server Native Client ODBC driver connects to an instance of SQL ServerSQL Server, the server detects that the client is using the SQL ServerSQL Server Native Client ODBC driver and sets several options on.

驅動程式本身會發出這些陳述式;ODBC 應用程式不用做任何事情就可以要求它們。The driver issues these statements itself; the ODBC application does nothing to request them. 設定這些選項可以使用驅動程式,讓 ODBC 應用程式更容易攜帶,因為伺服器行為會符合 ISO 標準。Setting these options allows ODBC applications using the driver to be more portable because the server behavior then matches the ISO standard.

以 DB-Library 為基礎的應用程式一般不會開啟這些選項。DB-Library-based applications generally do not turn these options on. 在執行相同的 SQL 語句時觀察 ODBC 或 DB-LIBRARY 用戶端間不同行為的網站,不應該假設這會指向 SQL ServerSQL Server Native Client ODBC 驅動程式的問題。Sites observing different behavior between ODBC or DB-Library clients when running the same SQL statement should not assume this points to a problem with the SQL ServerSQL Server Native Client ODBC driver. 它們應該先使用與 SQL ServerSQL Server Native Client ODBC 驅動程式所使用的相同 SET 選項,在 DB-LIBRARY 環境中重新執行語句。They should first rerun the statement in the DB-Library environment with the same SET options as would be used by the SQL ServerSQL Server Native Client ODBC driver.

由於使用者和應用程式可以隨時開啟和關閉 SET 選項,因此,預存程序和觸發程序的開發人員也應該在開啟和關閉以上列出的 SET 選項時,小心測試其程序和觸發程序。Because SET options can be turned on and off at any time by users and applications, developers of stored procedures and triggers should also take care to test their procedures and triggers with the SET options listed above turned both on and off. 無論特定連接叫用程序或觸發程序時已經設定哪些選項,這都可以確保程序和觸發程序能正常運作。This ensures that the procedures and triggers work correctly regardless of which options a particular connection may have set on when they invoke the procedure or trigger. 對於需要為這些選項的其中之一進行特定設定的觸發程序或預存程序,應該在觸發程序或預存程序開始時發出 SET 陳述式。Triggers or stored procedures that require a particular setting for one of these options should issue a SET statement at the start of the trigger or stored procedure. 此 SET 陳述式只有在執行觸發程序或預存程序時才有效,當程序或觸發程序結束時,就會還原原始的設定。This SET statement remains in effect only for the execution of the trigger or stored procedure; when the procedure or trigger ends, the original setting is restored.

連接到 SQL ServerSQL Server 的執行個體時,也會將第四個 SET 選項,也就是 CONCAT_NULL_YIELDS_NULL,設定為開啟。When connected to an instance of SQL ServerSQL Server, a fourth SET option, CONCAT_NULL_YIELDS_NULL, is also set on. 如果資料來源或SQLDriverConnectSQLBrowseConnect中指定了 AnsiNPW = No,則 SQL ServerSQL Server Native Client ODBC 驅動程式不會將這些選項設定為 on。The SQL ServerSQL Server Native Client ODBC driver does not set these options on if AnsiNPW=NO is specified in the data source or on either SQLDriverConnect or SQLBrowseConnect.

如同稍早所述的 ISO 選項,如果資料來源或SQLDriverConnectSQLBrowseConnect中指定了 QuotedID = No,則 SQL ServerSQL Server Native Client ODBC 驅動程式不會開啟 QUOTED_IDENTIFIER 選項。Like the ISO options noted earlier, the SQL ServerSQL Server Native Client ODBC driver does not turn the QUOTED_IDENTIFIER option on if QuotedID=NO is specified in the data source or on either SQLDriverConnect or SQLBrowseConnect.

為了讓驅動程式知道 SET 選項的目前狀態,ODBC 應用程式應該不會使用 Transact-SQLTransact-SQL SET 陳述式來設定這些選項。To allow the driver to know the current state of SET options, ODBC applications should not use the Transact-SQLTransact-SQL SET statement to set these options. 它們應該只會使用資料來源或連接選項設定這些選項。They should only set these options using either the data source or the connection options. 如果應用程式發出 SET 陳述式,此驅動程式可能會產生不正確的 SQL 陳述式。If the application issues SET statements, the driver can generate incorrect SQL statements.

另請參閱See Also

執行語句(ODBC) Executing Statements (ODBC)
SQLDriverConnect SQLDriverConnect
SQLBrowseConnectSQLBrowseConnect