搭配 SQL Server Native Client 使用連接字串關鍵字Using Connection String Keywords with SQL Server Native Client

適用於: 是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

某些 SQL ServerSQL Server Native Client API 會使用連接字串來指定連接屬性。Some SQL ServerSQL Server Native Client APIs use connection strings to specify connection attributes. 連接字串是關鍵字和關聯值的清單,每一個關鍵字都會識別特定的連接屬性。Connection strings are lists of keyword and associated values; each keyword identifies a particular connection attribute.

重要

SQL ServerSQL Server Native Client OLE DB (SQLNCLI)仍會被取代,而且不建議將它用於新的開發工作。The SQL ServerSQL Server Native Client OLE DB (SQLNCLI) remains deprecated and it is not recommended to use it for new development work. 請改為使用新的 Microsoft OLE DB Driver for SQL Server (MSOLEDBSQL),其會進行更新且具備最新的伺服器功能。Instead, use the new Microsoft OLE DB Driver for SQL Server (MSOLEDBSQL) which will be updated with the most recent server features.
如需詳細資訊,請參閱搭配使用連接字串關鍵字與 OLE DB 驅動程式 SQL ServerFor information, see Using Connection String Keywords with OLE DB Driver for SQL Server.

注意

SQL ServerSQL Server Native Client 允許模稜兩可的連接字串,以維護回溯相容性 (例如,某些關鍵字可能會指定一次以上,而且可能會允許衝突的關鍵字,好讓解決方法以位置或優先順序為根據)。Native Client allows ambiguity in connection strings to maintain backward compatibility (for example, some keywords may be specified more than once, and conflicting keywords may be allowed with resolution based on position or precedence). 當修改應用程式,以便使用 SQL ServerSQL Server Native Client 來移除對於模稜兩可之連接字串的任何相依性時,這就是很好的作法。It is good practice when modifying applications to use SQL ServerSQL Server Native Client to eliminate any dependency on connection string ambiguity.

下列章節描述當使用 SQL ServerSQL Server Native Client 當做資料提供者時,可以搭配 SQL ServerSQL Server Native Client OLE DB 提供者、SQL ServerSQL Server Native Client ODBC 驅動程式和 ActiveX Data Objects (ADO) 使用的關鍵字。The following sections describe the keywords that can be used with the SQL ServerSQL Server Native Client OLE DB provider, the SQL ServerSQL Server Native Client ODBC driver, and ActiveX Data Objects (ADO) when using SQL ServerSQL Server Native Client as the data provider.

ODBC 驅動程式連接字串關鍵字ODBC Driver connection string keywords

ODBC 應用程式會使用連接字串做為SQLDriverConnectSQLBrowseConnect函數的參數。ODBC applications use connection strings as a parameters to the SQLDriverConnect and SQLBrowseConnect functions.

ODBC 使用的連接字串具有以下語法:Connection strings used by ODBC have the following syntax:

connection-string ::= empty-string[;] | attribute[;] | attribute; connection-string

empty-string ::=

attribute ::= attribute-keyword=[{]attribute-value[}]

attribute-value ::= character-string

attribute-keyword ::= identifier

可以選擇用大括號括住屬性值,這樣是很好的作法。Attribute values can optionally be enclosed in braces, and it is good practice to do so. 如此可在屬性值包含非英數字元時避免問題發生。This avoids problems when attribute values contain non-alphanumeric characters. 值中的第一個右大括號應該會結束該值,所以值不能包含右大括號字元。The first closing brace in the value is assumed to terminate the value, so values cannot contain closing brace characters.

下表描述可搭配 ODBC 連接字串使用的關鍵字。The following table describes the keywords that may be used with an ODBC connection string.

關鍵字Keyword 說明Description
AddrAddr "Address" 的同義字。Synonym for "Address".
位址Address 執行 SQL ServerSQL Server 執行個體之伺服器的網路位址。The network address of the server running an instance of SQL ServerSQL Server. Address 通常是伺服器的網路名稱,不過也可能是其他名稱,例如管道、IP 位址,或 TCP/IP 通訊埠和通訊端位址。Address is usually the network name of the server, but can be other names such as a pipe, an IP address, or a TCP/IP port and socket address.

若您指定 IP 位址,請確定在 SQL ServerSQL Server 組態管理員中已啟用 TCP/IP 或具名管道通訊協定。If you specify an IP address, make sure that the TCP/IP or named pipes protocols are enabled in SQL ServerSQL Server Configuration Manager.

使用 SQL ServerSQL Server Native Client 時, Address的值會優先于 ODBC 連接字串中傳遞給伺服器的值。The value of Address takes precedence over the value passed to Server in ODBC connection strings when using SQL ServerSQL Server Native Client. 同時請注意,Address=; 將會連接到 Server 關鍵字中指定的伺服器,而 Address= ;, Address=.;Address=localhost;Address=(local); 都會造成與本機伺服器的連接。Also note that Address=; will connect to the server specified in the Server keyword, whereas Address= ;, Address=.;, Address=localhost;, and Address=(local); all cause a connection to the local server.

Address 關鍵字的完整語法如下:The complete syntax for the Address keyword is as follows:

[通訊協定 : ]位址[ , 連接埠 |\pipe\pipename][protocol:]Address[,port |\pipe\pipename]

protocol 可以是 tcp (TCP/IP)、 lpc (共用記憶體) 或 np (具名管道)。protocol can be tcp (TCP/IP), lpc (shared memory), or np (named pipes). 如需通訊協定的詳細資訊,請參閱設定用戶端通訊協定For more information about protocols, see Configure Client Protocols.

如果通訊協定網路關鍵字皆未指定,SQL ServerSQL Server Native Client 會使用 SQL ServerSQL Server Configuration Manager 中指定的通訊協定順序。If neither protocol nor the Network keyword is specified, SQL ServerSQL Server Native Client will use the protocol order specified in SQL ServerSQL Server Configuration Manager.

port 是在指定伺服器上所要連接的通訊埠。port is the port to connect to, on the specified server. 根據預設,SQL ServerSQL Server 會使用通訊埠 1433。By default, SQL ServerSQL Server uses port 1433.
AnsiNPWAnsiNPW 如果為 "yes",此驅動程式就會使用 ANSI 定義的行為來處理 NULL 比較、字元資料填補、警告和 NULL 串連。When "yes", the driver uses ANSI-defined behaviors for handling NULL comparisons, character data padding, warnings, and NULL concatenation. 當為 "no" 時,將不會公開 ANSI 定義的行為。When "no", ANSI defined behaviors are not exposed. 如需有關 ANSI NPW 行為的詳細資訊,請參閱ISO 選項的效果For more information about ANSI NPW behaviors, see Effects of ISO Options.
APPAPP 呼叫SQLDriverConnect的應用程式名稱(選擇性)。Name of the application calling SQLDriverConnect (optional). 如果指定的話,這個值會儲存在sysprocesses 資料program_name中,而且會由sp_whoAPP_NAME函數傳回。If specified, this value is stored in the master.dbo.sysprocesses column program_name and is returned by sp_who and the APP_NAME functions.
ApplicationIntentApplicationIntent 宣告連接到伺服器時的應用程式工作負載類型。Declares the application workload type when connecting to a server. 可能的值為 ReadOnlyReadWritePossible values are ReadOnly and ReadWrite. 預設值為ReadWriteThe default is ReadWrite. 例如:For example:

ApplicationIntent=ReadOnly

如需 SQL ServerSQL Server Native Client 支援 AlwaysOn 可用性群組Always On availability groups的詳細資訊,請參閱高可用性和嚴重損壞修復的 SQL Server Native Client 支援For more information about SQL ServerSQL Server Native Client's support for AlwaysOn 可用性群組Always On availability groups, see SQL Server Native Client Support for High Availability, Disaster Recovery.
AttachDBFileNameAttachDBFileName 可附加資料庫的主要檔案名稱。Name of the primary file of an attachable database. 包含完整路徑,而且會使用 C 字元字串變數逸出任何 \ 字元:Include the full path and escape any \ characters if using a C character string variable:

AttachDBFileName=c:\\MyFolder\\MyDB.mdf

此資料庫會附加,而且變成連接的預設資料庫。This database is attached and becomes the default database for the connection. 若要使用AttachDBFileName ,您也必須在SQLDriverConnect資料庫參數或 SQL_COPT_CURRENT_CATALOG 連接屬性中指定資料庫名稱。To use AttachDBFileName you must also specify the database name in either the SQLDriverConnect DATABASE parameter or the SQL_COPT_CURRENT_CATALOG connection attribute. 如果之前已附加資料庫,SQL ServerSQL Server 不會重新附加它,它會使用附加的資料庫當做連接的預設值。If the database was previously attached, SQL ServerSQL Server does not reattach it; it uses the attached database as the default for the connection.
AutoTranslateAutoTranslate 當為 "yes" 時,如果要轉譯用戶端與伺服器之間傳送的 ANSI 字元字串,則會透過 Unicode 來進行轉換,好讓用戶端與伺服器之字碼頁之間的比對擴充字元問題減至最少。When "yes", ANSI character strings sent between the client and server are translated by converting through Unicode to minimize problems in matching extended characters between the code pages on the client and the server.

傳送至 SQL ServerSQL Server CHARVarchartext變數、參數或資料行的用戶端 SQL_C_CHAR 資料會使用用戶端 ANSI 字碼頁(ACP)從字元轉換成 Unicode,然後使用的 ACP,從 unicode 轉換成字元。伺服器.Client SQL_C_CHAR data sent to a SQL ServerSQL Server char, varchar, or text variable, parameter, or column is converted from character to Unicode using the client ANSI code page (ACP), then converted from Unicode to character using the ACP of the server.

傳送至用戶端 SQL_C_CHAR 變數 SQL ServerSQL Server charVarcharTEXT資料會使用伺服器 ACP,從字元轉換成 UNICODE,然後使用用戶端 ACP 從 unicode 轉換成字元。SQL ServerSQL Server char, varchar, or text data sent to a client SQL_C_CHAR variable is converted from character to Unicode using the server ACP, then converted from Unicode to character using the client ACP.

這些轉換會由 SQL ServerSQL Server Native Client ODBC 驅動程式在用戶端上執行。These conversions are performed on the client by the SQL ServerSQL Server Native Client ODBC driver. 這會要求在伺服器上使用的相同 ANSI 字碼頁 (ACP) 必須也可以在用戶端上使用。This requires that the same ANSI code page (ACP) used on the server be available on the client.

這些設定對於進行下列傳輸時所發生的轉換沒有作用:These settings have no effect on the conversions that occur for these transfers:

* Unicode SQL_C_WCHAR 用戶端資料傳送至伺服器上的charVarchartext* Unicode SQL_C_WCHAR client data sent to char, varchar, or text on the server.

*傳送至用戶端上 Unicode SQL_C_WCHAR 變數的charVarchartext伺服器資料。* char, varchar, or text server data sent to a Unicode SQL_C_WCHAR variable on the client.

* ANSI SQL_C_CHAR 用戶端資料傳送至伺服器上的 Unicode NcharNvarcharNtext* ANSI SQL_C_CHAR client data sent to Unicode nchar, nvarchar, or ntext on the server.

* 傳送至用戶端上之 ANSI SQL_C_CHAR 變數的 Unicode NcharNvarcharNtext伺服器資料。* Unicode nchar, nvarchar, or ntext server data sent to an ANSI SQL_C_CHAR variable on the client.

當為 "no" 時,不會執行字元轉譯。When "no", character translation is not performed.

SQL ServerSQL Server Native Client ODBC 驅動程式不會將用戶端 ANSI 字元轉換 SQL_C_CHAR 的資料傳送至伺服器上的CHARVarchartext變數、參數或資料行。The SQL ServerSQL Server Native Client ODBC driver does not translate client ANSI character SQL_C_CHAR data sent to char, varchar, or text variables, parameters, or columns on the server. 不會在從伺服器傳送到用戶端上 SQL_C_CHAR 變數的charVarchartext資料上執行任何轉譯。No translation is performed on char, varchar, or text data sent from the server to SQL_C_CHAR variables on the client.

如果用戶端和 SQL ServerSQL Server 使用不同的 ACP,可能會將擴充字元解譯錯誤。If the client and SQL ServerSQL Server are using different ACPs, extended characters may be misinterpreted.
資料庫Database 用於連接的預設 SQL ServerSQL Server 資料庫名稱。Name of the default SQL ServerSQL Server database for the connection. 如果未指定database ,則會使用針對登入定義的預設資料庫。If Database is not specified, the default database defined for the login is used. ODBC 資料來源中的預設資料庫會覆寫針對此登入所定義的預設資料庫。The default database from the ODBC data source overrides the default database defined for the login. 除非也指定了AttachDBFileName ,否則資料庫必須是現有的資料庫。The database must be an existing database unless AttachDBFileName is also specified. 如果同時指定AttachDBFileName ,則會附加其指向的主要檔案,並提供資料庫指定的資料庫名稱。If AttachDBFileName is also specified, the primary file it points to is attached and given the database name specified by Database.
驅動程式Driver SQLDrivers所傳回的驅動程式名稱。Name of the driver as returned by SQLDrivers. SQL ServerSQL Server Native Client ODBC 驅動程式的關鍵字值是 "{SQL Server Native Client 11.0}"。The keyword value for the SQL ServerSQL Server Native Client ODBC driver is "{SQL Server Native Client 11.0}". 如果指定了Driver ,而且DriverCompletion設定為 SQL_DRIVER_NOPROMPT,則需要Server關鍵字。The Server keyword is required if Driver is specified and DriverCompletion is set to SQL_DRIVER_NOPROMPT.

如需驅動程式名稱的詳細資訊,請參閱使用 SQL Server Native Client 標頭檔和程式庫檔案。For more information about driver names, see Using the SQL Server Native Client Header and Library Files.
DSNDSN 現有 ODBC 使用者或系統資料來源的名稱。Name of an existing ODBC user or system data source. 此關鍵字會覆寫 [伺服器]、[網路] 和 [位址] 關鍵字中可能指定的任何值。This keyword overrides any values that might be specified in the Server, Network, and Address keywords.
EncryptEncrypt 指定當透過網路傳送資料以前,是否應該先加密資料。Specifies whether data should be encrypted before sending it over the network. 可能的值為 "yes" 和 "no"。Possible values are "yes" and "no". 預設值為 "no"。The default value is "no".
後援Fallback 這個關鍵字已被取代,而且 SQL ServerSQL Server Native Client ODBC 驅動程式會忽略它的設定。This keyword is deprecated, and its setting is ignored by the SQL ServerSQL Server Native Client ODBC driver.
Failover_PartnerFailover_Partner 當無法連接主要伺服器時,所要使用的容錯移轉夥伴伺服器名稱。Name of the failover partner server to be used if a connection cannot be made to the primary server.
FailoverPartnerSPNFailoverPartnerSPN 容錯移轉夥伴的 SPN。The SPN for the failover partner. 預設值為空字串。The default value is an empty string. 空字串會讓 SQL ServerSQL Server Native Client 使用驅動程式產生的預設 SPN。An empty string causes SQL ServerSQL Server Native Client to use the default, driver-generated SPN.
FileDSNFileDSN 現有 ODBC 檔案資料來源的名稱。Name of an existing ODBC file data source.
語言Language SQL ServerSQL Server 語言名稱 (選擇性)。language name (optional). SQL ServerSQL Server 可以在sysmessages中儲存多種語言的訊息。can store messages for multiple languages in sysmessages. 如果連接到使用多種語言的 SQL ServerSQL Server語言會指定要用於連接的訊息集。If connecting to a SQL ServerSQL Server with multiple languages, Language specifies which set of messages are used for the connection.
MARS_ConnectionMARS_Connection 啟用或停用連接上的 Multiple Active Result Sets (MARS)。Enables or disables multiple active result sets (MARS) on the connection. 可辨識的值為 "yes" 和 "no"。Recognized values are "yes" and "no". 預設值是 "no"。The default is "no".
MultiSubnetFailoverMultiSubnetFailover 當連接到 SQL ServerSQL Server 可用性群組的可用性群組接聽程式或 SQL ServerSQL Server 容錯移轉叢集實例時,一律指定multiSubnetFailover = YesAlways specify multiSubnetFailover=Yes when connecting to the availability group listener of a SQL ServerSQL Server availability group or a SQL ServerSQL Server Failover Cluster Instance. multiSubnetFailover = Yes會設定 SQL ServerSQL Server Native Client,以提供對(目前)使用中伺服器更快速的偵測與連接。multiSubnetFailover=Yes configures SQL ServerSQL Server Native Client to provide faster detection of and connection to the (currently) active server. 可能的值為 [是] 和 [否]。Possible values are Yes and No. 預設值為 NoThe default is No. 例如:For example:

MultiSubnetFailover=Yes

如需 SQL ServerSQL Server Native Client 支援 AlwaysOn 可用性群組Always On availability groups的詳細資訊,請參閱高可用性和嚴重損壞修復的 SQL Server Native Client 支援For more information about SQL ServerSQL Server Native Client's support for AlwaysOn 可用性群組Always On availability groups, see SQL Server Native Client Support for High Availability, Disaster Recovery.
NetNet "Network" 的同義字。Synonym for "Network".
NetworkNetwork 有效值為dbnmpntw (具名管道)和dbmssocn (tcp/ip)。Valid values are dbnmpntw (named pipes) and dbmssocn (TCP/IP).

指定Network關鍵字的值和Server關鍵字的通訊協定前置詞是錯誤的。It is an error to specify both a value for the Network keyword and a protocol prefix on the Server keyword.
PWDPWD 指定於 UID 參數中之 SQL ServerSQL Server 登入帳戶的密碼。The password for the SQL ServerSQL Server login account specified in the UID parameter. 如果登入具有 Null 密碼或使用 Windows 驗證(Trusted_Connection = yes),則不需要指定PWDPWD need not be specified if the login has a NULL password or when using Windows Authentication (Trusted_Connection = yes).
QueryLog_OnQueryLog_On 當為 "yes" 時,連接上會啟用長時間執行之查詢資料的記錄。When "yes", logging long-running query data is enabled on the connection. 當為 "no" 時,不會記錄長時間執行的查詢資料。When "no", long-running query data is not logged.
QueryLogFileQueryLogFile 用來記錄長時間執行之查詢資料的檔案完整路徑或檔案名稱。Full path and file name of a file to use to log data on long-running queries.
QueryLogTimeQueryLogTime 數字字元字串,可指定用來記錄長時間執行之查詢的臨界值 (以毫秒為單位)。Digit character string specifying the threshold (in milliseconds) for logging long-running queries. 在指定的時間內未得到回應的任何查詢都會寫入長時間執行的查詢記錄檔中。Any query that does not get a response in the time specified is written to the long-running query log file.
QuotedIdQuotedId 當為 "yes" 時,連接的 QUOTED_IDENTIFIERS 會設定為 ON,而且 SQL ServerSQL Server 會使用 ISO 規則,不論 SQL 陳述式中是否使用引號。When "yes", QUOTED_IDENTIFIERS is set ON for the connection, SQL ServerSQL Server uses the ISO rules regarding the use of quotation marks in SQL statements. 當設定為 no 時,連接的 QUOTED_IDENTIFIERS 會設定為 OFF,When no, QUOTED_IDENTIFIERS is set OFF for the connection. 然後 SQL ServerSQL Server 會遵循 Transact-SQLTransact-SQL 傳統規則,不論 SQL 陳述式中是否使用引號。SQL ServerSQL Server then follows the legacy Transact-SQLTransact-SQL rules regarding the use of quotation marks in SQL statements. 如需詳細資訊,請參閱ISO 選項的效果For more information, see Effects of ISO Options.
RegionalRegional 當設定為 "yes" 時,SQL ServerSQL Server Native Client ODBC 驅動程式將貨幣、日期和時間資料轉換成字元資料時,會使用用戶端設定。When "yes", the SQL ServerSQL Server Native Client ODBC driver uses client settings when converting currency, date, and time data to character data. 轉換僅限單向;此驅動程式無法辨識非 ODBC 標準格式的日期字串或貨幣值;例如,INSERT 或 UPDATE 陳述式中使用的參數。The conversion is one way only; the driver does not recognize non-ODBC standard formats for date strings or currency values within; for example, a parameter used in an INSERT or UPDATE statement. 當設定為 "no" 時,此驅動程式會使用 ODBC 標準字串來表示轉換成字元資料的貨幣、日期和時間資料。When "no", the driver uses ODBC standard strings to represent currency, date, and time data that is converted to character data.
SaveFileSaveFile 如果連接成功,要用來儲存目前連接之屬性的 ODBC 資料來源檔案名稱。Name of an ODBC data source file into which the attributes of the current connection are saved if the connection is successful.
ServerServer SQL ServerSQL Server 執行個體的名稱。The name of a SQL ServerSQL Server instance. 此值必須是網路上的伺服器名稱、IP 位址,或是 SQL ServerSQL Server 組態管理員別名的名稱。The value must be either the name of a server on the network, an IP address, or the name of a SQL ServerSQL Server Configuration Manager alias.

Address關鍵字會覆寫Server關鍵字。The Address keyword overrides the Server keyword.

您可藉由指定下列其中一個項目,連接到本機伺服器上的預設執行個體:You can connect to the default instance on the local server by specifying one of the following:

伺服器=;Server=;

伺服器=.;Server=.;

伺服器=(local);Server=(local);

伺服器=(local);Server=(local);

伺服器=(localhost);Server=(localhost);

伺服器=(localdb)\ 執行個體名稱 ;Server=(localdb)\ instancename ;

如需 LocalDB 支援的詳細資訊,請參閱SQL Server Native Client 對 localdb 的支援For more information about LocalDB support, see SQL Server Native Client Support for LocalDB.

若要指定的具名執行個體SQL ServerSQL Server,附加 \ InstanceNameTo specify a named instance of SQL ServerSQL Server, append \InstanceName.

如果未指定伺服器,就會連接到本機電腦上的預設執行個體。When no server is specified, a connection is made to the default instance on the local computer.

若您指定 IP 位址,請確定在 SQL ServerSQL Server 組態管理員中已啟用 TCP/IP 或具名管道通訊協定。If you specify an IP address, make sure that the TCP/IP or named pipes protocols are enabled in SQL ServerSQL Server Configuration Manager.

Server 關鍵字的完整語法如下:The complete syntax for the Server keyword is as follows:

伺服器= [通訊協定 : ]伺服器[ , 連接埠]Server=[protocol:]Server[,port]

protocol 可以是 tcp (TCP/IP)、 lpc (共用記憶體) 或 np (具名管道)。protocol can be tcp (TCP/IP), lpc (shared memory), or np (named pipes).

下列是指定具名管道的範例:The following is an example of specifying a named pipe:

np:\\.\pipe\MSSQL$MYINST01\sql\query

此程式碼行指定具名管道通訊協定、本機電腦上的具名管道 (\\.\pipe)、SQL ServerSQL Server 執行個體的名稱 (MSSQL$MYINST01) 以及具名管道的預設名稱 (sql/query)。This line specifies named pipe protocol, a named pipe on the local machine (\\.\pipe), the name of the SQL ServerSQL Server instance (MSSQL$MYINST01), and the default name of the named pipe (sql/query).

如果未指定通訊協定網路關鍵字,SQL ServerSQL Server Native Client 會使用 SQL ServerSQL Server Configuration Manager 中指定的通訊協定順序。If neither a protocol nor the Network keyword is specified, SQL ServerSQL Server Native Client will use the protocol order specified in SQL ServerSQL Server Configuration Manager.

port 是在指定伺服器上所要連接的通訊埠。port is the port to connect to, on the specified server. 根據預設,SQL ServerSQL Server 會使用通訊埠 1433。By default, SQL ServerSQL Server uses port 1433.

使用 SQL ServerSQL Server Native Client 時,在 ODBC 連接字串中傳遞至伺服器的值開頭會忽略空格。Spaces are ignored at the beginning of the value passed to Server in ODBC connection strings when using SQL ServerSQL Server Native Client.
ServerSPNServerSPN 伺服器的 SPN。The SPN for the server. 預設值為空字串。The default value is an empty string. 空字串會讓 SQL ServerSQL Server Native Client 使用驅動程式產生的預設 SPN。An empty string causes SQL ServerSQL Server Native Client to use the default, driver-generated SPN.
StatsLog_OnStatsLog_On 當設定為 "yes" 時,會啟用 SQL ServerSQL Server Native Client ODBC 驅動程式效能資料的擷取。When "yes", enables the capture of SQL ServerSQL Server Native Client ODBC driver performance data. 當設定為 "no" 時,連接上無法取得 SQL ServerSQL Server Native Client ODBC 驅動程式效能資料。When "no", SQL ServerSQL Server Native Client ODBC driver performance data is not available on the connection.
StatsLogFileStatsLogFile 用來記錄 SQL ServerSQL Server Native Client ODBC 驅動程式效能統計資料之檔案的完整路徑和檔案名稱。Full path and file name of a file used to record SQL ServerSQL Server Native Client ODBC driver performance statistics.
Trusted_ConnectionTrusted_Connection 當為 "yes" 時,會指示 SQL ServerSQL Server Native Client ODBC 驅動程式使用 Windows 驗證模式進行登入驗證。When "yes", instructs the SQL ServerSQL Server Native Client ODBC driver to use Windows Authentication Mode for login validation. 否則會指示 SQL ServerSQL Server Native Client ODBC 驅動程式使用 SQL ServerSQL Server 使用者名稱和密碼進行登入驗證,而且必須指定 UID 和 PWD 密碼。Otherwise instructs the SQL ServerSQL Server Native Client ODBC driver to use a SQL ServerSQL Server username and password for login validation, and the UID and PWD keywords must be specified.
TrustServerCertificateTrustServerCertificate 與 encryption 搭配使用時,會使用自我簽署的伺服器證書來啟用加密。When used with Encrypt, enables encryption using a self-signed server certificate.
UIDUID 有效的 SQL ServerSQL Server 登入帳戶。A valid SQL ServerSQL Server login account. 使用 Windows 驗證時不需要指定 UID。UID need not be specified when using Windows Authentication.
UseProcForPrepareUseProcForPrepare 這個關鍵字已被取代,而且 SQL ServerSQL Server Native Client ODBC 驅動程式會忽略它的設定。This keyword is deprecated, and its setting is ignored by the SQL ServerSQL Server Native Client ODBC Driver.
WSIDWSID 工作站識別碼。The workstation ID. 一般而言,這是應用程式所在之電腦的網路名稱 (選擇性)。Typically, this is the network name of the computer on which the application resides (optional). 如果指定,這個值會儲存在sysprocesses 資料主機名稱中,而且會由sp_whoHOST_NAME函數傳回。If specified, this value is stored in the master.dbo.sysprocesses column hostname and is returned by sp_who and the HOST_NAME function.

注意: 地區轉換設定適用于貨幣、數值、日期和時間資料類型。NOTE: Regional conversion settings apply to currency, numeric, date, and time data types. 此轉換設定只適用於輸出轉換,而且只有當貨幣、數值、日期或時間值轉換為字元字串時,才能看到。The conversion setting is only applicable to output conversion and is only visible when currency, numeric, date, or time values are converted to character strings.

SQL ServerSQL Server Native Client ODBC 驅動程式會針對目前的使用者使用地區設定的登錄設定。The SQL ServerSQL Server Native Client ODBC driver uses the locale registry settings for the current user. 如果應用程式在連接之後設定它,例如呼叫SetThreadLocale,則驅動程式不接受目前線程的地區設定。The driver does not honor the current thread's locale if the application sets it after connection by, for example, calling SetThreadLocale.

變更資料來源的地區行為可能會導致應用程式失敗。Altering the regional behavior of a data source can cause application failure. 剖析日期字串並預期日期字串如 ODBC 定義之方式顯示的應用程式,可能會受到變更此值的負面影響。An application that parses date strings, and expects date strings to appear as defined by ODBC, could be adversely affected by altering this value.

OLE DB 提供者連接字串關鍵字OLE DB Provider Connection String Keywords

OLE DB 應用程式有兩種方法可初始化資料來源物件:There are two ways OLE DB applications can initialize data source objects:

  • IDBInitialize::InitializeIDBInitialize::Initialize

  • IDataInitialize::GetDataSourceIDataInitialize::GetDataSource

在第一個案例中,提供者字串可用來初始化連接屬性,其方式是在 DBPROPSET_DBINIT 屬性集中設定 DBPROP_INIT_PROVIDERSTRING 屬性。In the first case, a provider string can be used to initialize connection properties by setting the property DBPROP_INIT_PROVIDERSTRING in the DBPROPSET_DBINIT property set. 在第二個案例中,初始化字串可以傳遞給 IDataInitialize::GetDataSource 方法來初始化連接屬性。In the second case, an initialization string can be passed to IDataInitialize::GetDataSource method to initialize connection properties. 這兩個方法都會初始化相同的 OLE DB 連接屬性,但是會使用不同的關鍵字集合。Both methods initialize the same OLE DB connection properties, but different sets of keywords are used. IDataInitialize::GetDataSource 所使用的關鍵字集合,至少是初始化屬性群組內的屬性描述。The set of keywords used by IDataInitialize::GetDataSource is at minimum the description of properties within the initialization property group.

如果任何提供者字串設定所包含的對應 OLE DB 屬性設定為預設值或明確設定為某個值,OLE DB 屬性值將在提供者字串中覆寫此設定。Any provider string setting that has a corresponding OLE DB property set to some default value or explicitly set to a value, the OLE DB property value will override the setting in the provider string.

在提供者字串中透過 DBPROP_INIT_PROVIDERSTRING 值所設定的布林屬性是使用 "yes" 和 "no" 的值所設定。Boolean properties set in provider strings via DBPROP_INIT_PROVIDERSTRING values are set using the values "yes" and "no". 在初始化字串中使用 IDataInitialize::GetDataSource 所設定的布林值屬性,是使用 "True" 和 "False" 的值所設定。Boolean properties set in initialization strings using IDataInitialize::GetDataSource are set using the values "true" and "false".

使用 IDataInitialize::GetDataSource 的應用程式,也可以使用 IDBInitialize::Initialize 所用的關鍵字,但是只適用於沒有預設值的屬性。Applications using IDataInitialize::GetDataSource can also use the keywords used by IDBInitialize::Initialize but only for properties that do not have a default value. 如果應用程式在初始化字串中同時使用 IDataInitialize::GetDataSource 關鍵字和 IDBInitialize::Initialize 關鍵字,則會使用 IDataInitialize::GetDataSource 關鍵字設定。If an application uses both the IDataInitialize::GetDataSource keyword and the IDBInitialize::Initialize keyword in the initialization string, the IDataInitialize::GetDataSource keyword setting is used. 強烈建議您不要讓應用程式在 IDataInitialize:GetDataSource 連接字串中使用 IDBInitialize::Initialize 關鍵字,因為將來的版本可能無法維護這個行為。It is strongly recommended that applications do not use IDBInitialize::Initialize keywords in IDataInitialize:GetDataSource connection strings, as this behavior may not be maintained in future releases.

注意

透過 IDataInitialize::GetDataSource 傳遞的連接字串會經由 IDBProperties::SetProperties 轉換成屬性並加以套用。A connection string passed through IDataInitialize::GetDataSource is converted into properties and applied via IDBProperties::SetProperties. 如果元件服務在 IDBProperties::GetPropertyInfo 中找到屬性描述,此屬性將會作為獨立屬性來套用。If component services found the property description in IDBProperties::GetPropertyInfo, this property will be applied as a stand-alone property. 否則,它將會透過 DBPROP_PROVIDERSTRING 屬性來套用。Otherwise, it will be applied through DBPROP_PROVIDERSTRING property. 例如,如果您指定連接字串資料來源 = server1;Server = server2資料來源將會設定為屬性,但是伺服器會進入提供者字串。For example, if you specify connection string Data Source=server1;Server=server2, Data Source will be set as a property, but Server will go into a provider string.

如果您指定相同提供者特有之屬性的多個執行個體,將會使用第一個屬性的值。If you specify multiple instances of the same provider-specific property, the first value of the first property will be used.

OLE DB 應用程式使用的連接字串如果搭配 IDBInitialize::Initialize 使用 DBPROP_INIT_PROVIDERSTRING,其語法如下:Connection strings used by OLE DB applications using DBPROP_INIT_PROVIDERSTRING with IDBInitialize::Initialize have the following syntax:

connection-string ::= empty-string[;] | attribute[;] | attribute; connection-string

empty-string ::=

attribute ::= attribute-keyword=[{]attribute-value[}]

attribute-value ::= character-string

attribute-keyword ::= identifier

可以選擇用大括號括住屬性值,這樣是很好的作法。Attribute values can optionally be enclosed in braces, and it is good practice to do so. 如此可在屬性值包含非英數字元時避免問題發生。This avoids problems when attribute values contain non-alphanumeric characters. 值中的第一個右大括號應該會結束該值,所以值不能包含右大括號字元。The first closing brace in the value is assumed to terminate the value, so values cannot contain closing brace characters.

連接字串關鍵字 = 符號後面的空格字元應該解譯為常值,即使該值括在引號內也是如此。A space character after the = sign of a connection string keyword will be interpreted as a literal, even if the value is enclosed in quotation marks.

下表描述可搭配 DBPROP_INIT_PROVIDERSTRING 使用的關鍵字。The following table describes the keywords that may be used with DBPROP_INIT_PROVIDERSTRING.

關鍵字Keyword 初始化屬性Initialization property 說明Description
AddrAddr SSPROP_INIT_NETWORKADDRESSSSPROP_INIT_NETWORKADDRESS "Address" 的同義字。Synonym for "Address".
位址Address SSPROP_INIT_NETWORKADDRESSSSPROP_INIT_NETWORKADDRESS 組織中 SQL ServerSQL Server 執行個體的網路位址。The network address of an instance of SQL ServerSQL Server in the organization.

如需有關有效位址語法的詳細資訊,請參閱本主題稍後的address ODBC 關鍵字的說明。For more information about valid address syntax, see the description of the Address ODBC keyword, later in this topic.
APPAPP SSPROP_INIT_APPNAMESSPROP_INIT_APPNAME 識別應用程式的字串。The string identifying the application.
ApplicationIntentApplicationIntent SSPROP_INIT_APPLICATIONINTENTSSPROP_INIT_APPLICATIONINTENT 宣告連接到伺服器時的應用程式工作負載類型。Declares the application workload type when connecting to a server. 可能的值為 ReadOnlyReadWritePossible values are ReadOnly and ReadWrite.

預設值為ReadWriteThe default is ReadWrite. 如需 SQL ServerSQL Server Native Client 支援 AlwaysOn 可用性群組Always On availability groups的詳細資訊,請參閱高可用性和嚴重損壞修復的 SQL Server Native Client 支援For more information about SQL ServerSQL Server Native Client's support for AlwaysOn 可用性群組Always On availability groups, see SQL Server Native Client Support for High Availability, Disaster Recovery.
AttachDBFileNameAttachDBFileName SSPROP_INIT_FILENAMESSPROP_INIT_FILENAME 可附加資料庫的主要檔案名稱,包括完整路徑名稱。The name of the primary file (include the full path name) of an attachable database. 若要使用 AttachDBFileName,您還必須使用提供者字串 Database 關鍵字來指定資料庫名稱。To use AttachDBFileName, you must also specify the database name with the provider string Database keyword. 如果之前已附加資料庫,SQL ServerSQL Server 不會重新附加它 (它會使用附加的資料庫當做連接的預設值)。If the database was previously attached, SQL ServerSQL Server does not reattach it (it uses the attached database as the default for the connection).
自動轉譯Auto Translate SSPROP_INIT_AUTOTRANSLATESSPROP_INIT_AUTOTRANSLATE "AutoTranslate" 的同義字。Synonym for "AutoTranslate".
AutoTranslateAutoTranslate SSPROP_INIT_AUTOTRANSLATESSPROP_INIT_AUTOTRANSLATE 設定 OEM/ANSI 字元轉譯。Configures OEM/ANSI character translation. 可辨識的值為 "yes" 和 "no"。Recognized values are "yes" and "no".
資料庫Database DBPROP_INIT_CATALOGDBPROP_INIT_CATALOG 資料庫名稱。The database name.
DataTypeCompatibilityDataTypeCompatibility SSPROP_INIT_DATATYPECOMPATIBILITYSSPROP_INIT_DATATYPECOMPATIBILITY 指定要使用的資料類型處理模式。Specifies the mode of data type handling to use. 認得的值為 "0" (代表提供者資料類型) 和 "80" (代表 SQL Server 2000 資料類型)。Recognized values are "0" for provider data types and "80" for SQL Server 2000 data types.
EncryptEncrypt SSPROP_INIT_ENCRYPTSSPROP_INIT_ENCRYPT 指定當透過網路傳送資料以前,是否應該先加密資料。Specifies whether data should be encrypted before sending it over the network. 可能的值為 "yes" 和 "no"。Possible values are "yes" and "no". 預設值為 "no"。The default value is "no".
FailoverPartnerFailoverPartner SSPROP_INIT_FAILOVERPARTNERSSPROP_INIT_FAILOVERPARTNER 用於資料庫鏡像的容錯移轉伺服器名稱。The name of the failover server used for database mirroring.
FailoverPartnerSPNFailoverPartnerSPN SSPROP_INIT_FAILOVERPARTNERSPNSSPROP_INIT_FAILOVERPARTNERSPN 容錯移轉夥伴的 SPN。The SPN for the failover partner. 預設值為空字串。The default value is an empty string. 空字串會讓 SQL ServerSQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes SQL ServerSQL Server Native Client to use the default, provider-generated SPN.
語言Language SSPROPT_INIT_CURRENTLANGUAGESSPROPT_INIT_CURRENTLANGUAGE SQL ServerSQL Server 語言。The SQL ServerSQL Server language.
MarsConnMarsConn SSPROP_INIT_MARSCONNECTIONSSPROP_INIT_MARSCONNECTION 當伺服器為 SQL Server 2005 (9.x)SQL Server 2005 (9.x) 或更新版本時,啟用或停用連接上的 Multiple Active Result Sets (MARS)。Enables or disables multiple active result sets (MARS) on the connection if the server is SQL Server 2005 (9.x)SQL Server 2005 (9.x) or later. 可能的值為 "yes" 和 "no"。Possible values are "yes" and "no". 預設值為 "no"。The default value is "no".
NetNet SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY "Network" 的同義字。Synonym for "Network".
NetworkNetwork SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY 用來建立組織中 SQL ServerSQL Server 執行個體之連接的網路程式庫。The network library used to establish a connection to an instance of SQL ServerSQL Server in the organization.
Network LibraryNetwork Library SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY "Network" 的同義字。Synonym for "Network".
PacketSizePacketSize SSPROP_INIT_PACKETSIZESSPROP_INIT_PACKETSIZE 網路封包大小。Network packet size. 預設值是 4096。The default is 4096.
PersistSensitivePersistSensitive DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFODBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO 接受的值為 "yes" 和 "no" 字串。Accepts the strings "yes" and "no" as values. 當為 "no" 時,不允許使用資料來源物件來保存敏感性驗證資訊。When "no", the data source object is not allowed to persist sensitive authentication information
PWDPWD DBPROP_AUTH_PASSWORDDBPROP_AUTH_PASSWORD SQL ServerSQL Server 登入密碼。The SQL ServerSQL Server login password.
ServerServer DBPROP_INIT_DATASOURCEDBPROP_INIT_DATASOURCE 組織中 SQL ServerSQL Server 執行個體的名稱。The name of an instance of SQL ServerSQL Server in the organization.

如果沒有指定,就會連接至本機電腦上的預設執行個體。When not specified, a connection is made to the default instance on the local computer.

如需有關有效位址語法的詳細資訊,請參閱本主題中的Server ODBC 關鍵字的說明。For more information about valid address syntax, see the description of the Server ODBC keyword, in this topic.
ServerSPNServerSPN SSPROP_INIT_SERVERSPNSSPROP_INIT_SERVERSPN 伺服器的 SPN。The SPN for the server. 預設值為空字串。The default value is an empty string. 空字串會讓 SQL ServerSQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes SQL ServerSQL Server Native Client to use the default, provider-generated SPN.
逾時Timeout DBPROP_INIT_TIMEOUTDBPROP_INIT_TIMEOUT 等候資料來源初始化完成的時間量 (以秒為單位)。The amount of time (in seconds) to wait for data source initialization to complete.
Trusted_ConnectionTrusted_Connection DBPROP_AUTH_INTEGRATEDDBPROP_AUTH_INTEGRATED 當為 "yes" 時,會指示 SQL ServerSQL Server Native Client OLE DB 提供者使用 Windows 驗證模式進行登入驗證。When "yes", instructs the SQL ServerSQL Server Native Client OLE DB provider to use Windows Authentication Mode for login validation. 否則會指示 SQL ServerSQL Server Native Client OLE DB 提供者使用 SQL ServerSQL Server 使用者名稱和密碼進行登入驗證,而且必須指定 UID 和 PWD 密碼。Otherwise instructs the SQL ServerSQL Server Native Client OLE DB provider to use a SQL ServerSQL Server username and password for login validation, and the UID and PWD keywords must be specified.
TrustServerCertificateTrustServerCertificate SSPROP_INIT_TRUST_SERVER_CERTIFICATESSPROP_INIT_TRUST_SERVER_CERTIFICATE 接受的值為 "yes" 和 "no" 字串。Accepts the strings "yes" and "no" as values. 預設值為 "no",這表示將會驗證伺服器憑證。The default value is "no", which means that the server certificate will be validated.
UIDUID DBPROP_AUTH_USERIDDBPROP_AUTH_USERID SQL ServerSQL Server 登入名稱。The SQL ServerSQL Server login name.
UseProcForPrepareUseProcForPrepare SSPROP_INIT_USEPROCFORPREPSSPROP_INIT_USEPROCFORPREP 這個關鍵字已被取代,而且 SQL ServerSQL Server Native Client OLE DB 提供者會忽略它的設定。This keyword is deprecated, and its setting is ignored by the SQL ServerSQL Server Native Client OLE DB Provider.
WSIDWSID SSPROP_INIT_WSIDSSPROP_INIT_WSID 工作站識別碼。The workstation identifier.

OLE DB 應用程式使用的連接字串如果使用 IDataInitialize::GetDataSource,其語法如下:Connection strings used by OLE DB applications using IDataInitialize::GetDataSource have the following syntax:

connection-string ::= empty-string[;] | attribute[;] | attribute; connection-string

empty-string ::=

attribute ::= attribute-keyword=[quote]attribute-value[quote]

attribute-value ::= character-string

attribute-keyword ::= identifier

quote ::= " | '

屬性的使用必須符合其範圍內所允許的語法。 例如,WSID 會使用大括號 ( {} ) 字元,而 Application Name 會使用單引號 ( ' ) 或雙引號 ( " ) 字元。 只有字串屬性可以加上引號。Only string properties can be quoted. 嘗試將整數或列舉屬性加上引號將會產生「連接字串沒有符合 OLE DB 規格」錯誤。Attempting to quote an integer or enumerated property will result in a "Connection String does not conform to OLE DB specification" error.

您可以選擇用單引號或雙引號括住屬性值,這樣是很好的作法。Attribute values can optionally be enclosed in single or double quotes, and it is good practice to do so. 如此可在值包含非英數字元時避免問題發生。This avoids problems when values contain non-alphanumeric characters. 使用的引號字元也可出現在值當中,但前提必須是雙引號字元。The quote character used can also appear in values, provided that it is doubled.

連接字串關鍵字 = 符號後面的空格字元應該解譯為常值,即使該值括在引號內也是如此。A space character after the = sign of a connection string keyword will be interpreted as a literal, even if the value is enclosed in quotation marks.

如果連接字串具有下表所列的多個屬性,將會使用最後一個屬性的值。If a connection string has more than one of the properties listed in the following table, the value of the last property will be used.

下表說明可搭配 IDataInitialize::GetDataSource 使用的關鍵字:The following table describes the keywords that may be used with IDataInitialize::GetDataSource:

關鍵字Keyword 初始化屬性Initialization property 說明Description
應用程式名稱Application Name SSPROP_INIT_APPNAMESSPROP_INIT_APPNAME 識別應用程式的字串。The string identifying the application.
Application IntentApplication Intent SSPROP_INIT_APPLICATIONINTENTSSPROP_INIT_APPLICATIONINTENT 宣告連接到伺服器時的應用程式工作負載類型。Declares the application workload type when connecting to a server. 可能的值為 ReadOnlyReadWritePossible values are ReadOnly and ReadWrite.

預設值為ReadWriteThe default is ReadWrite. 如需 SQL ServerSQL Server Native Client 支援 AlwaysOn 可用性群組Always On availability groups的詳細資訊,請參閱高可用性和嚴重損壞修復的 SQL Server Native Client 支援For more information about SQL ServerSQL Server Native Client's support for AlwaysOn 可用性群組Always On availability groups, see SQL Server Native Client Support for High Availability, Disaster Recovery.
自動轉譯Auto Translate SSPROP_INIT_AUTOTRANSLATESSPROP_INIT_AUTOTRANSLATE "AutoTranslate" 的同義字。Synonym for "AutoTranslate".
AutoTranslateAutoTranslate SSPROP_INIT_AUTOTRANSLATESSPROP_INIT_AUTOTRANSLATE 設定 OEM/ANSI 字元轉譯。Configures OEM/ANSI character translation. 認得的值為 "true" 和 "false"。Recognized values are "true" and "false".
連接逾時Connect Timeout DBPROP_INIT_TIMEOUTDBPROP_INIT_TIMEOUT 等候資料來源初始化完成的時間量 (以秒為單位)。The amount of time (in seconds) to wait for data source initialization to complete.
Current LanguageCurrent Language SSPROPT_INIT_CURRENTLANGUAGESSPROPT_INIT_CURRENTLANGUAGE SQL ServerSQL Server 語言名稱。The SQL ServerSQL Server language name.
資料來源Data Source DBPROP_INIT_DATASOURCEDBPROP_INIT_DATASOURCE 組織中 SQL ServerSQL Server 執行個體的名稱。The name of an instance of SQL ServerSQL Server in the organization.

如果沒有指定,就會連接至本機電腦上的預設執行個體。When not specified, a connection is made to the default instance on the local computer.

如需有關有效位址語法的詳細資訊,請參閱本主題稍後的Server ODBC 關鍵字的說明。For more information about valid address syntax, see the description of the Server ODBC keyword, later in this topic.
DataTypeCompatibilityDataTypeCompatibility SSPROP_INIT_DATATYPECOMPATIBILITYSSPROP_INIT_DATATYPECOMPATIBILITY 指定要使用的資料類型處理模式。Specifies the mode of data type handling to use. 認得的值為 "0" (代表提供者資料類型) 和 "80" (代表 SQL Server 2000 (8.x)SQL Server 2000 (8.x) 資料類型)。Recognized values are "0" for provider data types and "80" for SQL Server 2000 (8.x)SQL Server 2000 (8.x) data types.
Failover PartnerFailover Partner SSPROP_INIT_FAILOVERPARTNERSSPROP_INIT_FAILOVERPARTNER 用於資料庫鏡像的容錯移轉伺服器名稱。The name of the failover server used for database mirroring.
Failover Partner SPNFailover Partner SPN SSPROP_INIT_FAILOVERPARTNERSPNSSPROP_INIT_FAILOVERPARTNERSPN 容錯移轉夥伴的 SPN。The SPN for the failover partner. 預設值為空字串。The default value is an empty string. 空字串會讓 SQL ServerSQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes SQL ServerSQL Server Native Client to use the default, provider-generated SPN.
初始目錄Initial Catalog DBPROP_INIT_CATALOGDBPROP_INIT_CATALOG 資料庫名稱。The database name.
初始檔案名稱Initial File Name SSPROP_INIT_FILENAMESSPROP_INIT_FILENAME 可附加資料庫的主要檔案名稱,包括完整路徑名稱。The name of the primary file (include the full path name) of an attachable database. 若要使用 AttachDBFileName,您還必須使用提供者字串 DATABASE 關鍵字來指定資料庫名稱。To use AttachDBFileName, you must also specify the database name with the provider string DATABASE keyword. 如果之前已附加資料庫,SQL ServerSQL Server 不會重新附加它 (它會使用附加的資料庫當做連接的預設值)。If the database was previously attached, SQL ServerSQL Server does not reattach it (it uses the attached database as the default for the connection).
整合式安全性Integrated Security DBPROP_AUTH_INTEGRATEDDBPROP_AUTH_INTEGRATED 接受 "SSPI" 值進行 Windows 驗證。Accepts the value "SSPI" for Windows Authentication.
MARS ConnectionMARS Connection SSPROP_INIT_MARSCONNECTIONSSPROP_INIT_MARSCONNECTION 啟用或停用連接上的 Multiple Active Result Sets (MARS)。Enables or disables multiple active result sets (MARS) on the connection. 認得的值為 "true" 和 "false"。Recognized values are "true" and "false". 預設值為 "false"。The default is "false".
Network AddressNetwork Address SSPROP_INIT_NETWORKADDRESSSSPROP_INIT_NETWORKADDRESS 組織中 SQL ServerSQL Server 執行個體的網路位址。The network address of an instance of SQL ServerSQL Server in the organization.

如需有關有效位址語法的詳細資訊,請參閱本主題稍後的address ODBC 關鍵字的說明。For more information about valid address syntax, see the description of the Address ODBC keyword, later in this topic.
Network LibraryNetwork Library SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY 用來建立組織中 SQL ServerSQL Server 執行個體之連接的網路程式庫。The network library used to establish a connection to an instance of SQL ServerSQL Server in the organization.
封包大小Packet Size SSPROP_INIT_PACKETSIZESSPROP_INIT_PACKETSIZE 網路封包大小。Network packet size. 預設值是 4096。The default is 4096.
密碼Password DBPROP_AUTH_PASSWORDDBPROP_AUTH_PASSWORD SQL ServerSQL Server 登入密碼。The SQL ServerSQL Server login password.
保存安全性資訊Persist Security Info DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFODBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO 接受的值為 "true" 和 "false" 字串。Accepts the strings "true" and "false" as values. 當為 "false" 時,不允許使用資料來源物件來保存敏感性驗證資訊。When "false", the data source object is not allowed to persist sensitive authentication information
提供者Provider 如果是 SQL ServerSQL Server Native Client,這應該是 "SQLNCLI11"。For SQL ServerSQL Server Native Client, this should be "SQLNCLI11".
Server SPNServer SPN SSPROP_INIT_SERVERSPNSSPROP_INIT_SERVERSPN 伺服器的 SPN。The SPN for the server. 預設值為空字串。The default value is an empty string. 空字串會讓 SQL ServerSQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes SQL ServerSQL Server Native Client to use the default, provider-generated SPN.
信任伺服器憑證Trust Server Certificate SSPROP_INIT_TRUST_SERVER_CERTIFICATESSPROP_INIT_TRUST_SERVER_CERTIFICATE 接受的值為 "true" 和 "false" 字串。Accepts the strings "true" and "false" as values. 預設值為 "false",這表示將會驗證伺服器憑證。The default value is "false", which means that the server certificate will be validated.
使用加密資料Use Encryption for Data SSPROP_INIT_ENCRYPTSSPROP_INIT_ENCRYPT 指定當透過網路傳送資料以前,是否應該先加密資料。Specifies whether data should be encrypted before sending it over the network. 可能的值為 "true" 和 "false"。Possible values are "true" and "false". 預設值為 "false"。The default value is "false".
使用者識別碼User ID DBPROP_AUTH_USERIDDBPROP_AUTH_USERID SQL ServerSQL Server 登入名稱。The SQL ServerSQL Server login name.
Workstation IDWorkstation ID SSPROP_INIT_WSIDSSPROP_INIT_WSID 工作站識別碼。The workstation identifier.

請注意:在此連接字串中,"Old Password" 屬性會設定 SSPROP_AUTH_OLD_PASSWORD,這是無法透過提供者字串屬性取得的目前密碼 (可能已過期)。Note In the connection string, the "Old Password" property sets SSPROP_AUTH_OLD_PASSWORD, which is the current (possibly expired) password that is not available via a provider string property.

ActiveX Data Objects (ADO) 連接字串關鍵字ActiveX Data Objects (ADO) Connection String Keywords

ADO 應用程式會設定 ADODBConnection 物件的 ConnectionString 屬性,或是提供連接字串當做 ADODBConnection 物件之 Open 方法的參數。ADO applications set the ConnectionString property of ADODBConnection objects or supply a connection string as a parameter to the Open method of ADODBConnection objects.

ADO 應用程式也可以使用 OLE DB IDBInitialize::Initialize 方法所使用的關鍵字,但是只適用於沒有預設值的屬性。ADO applications can also use the keywords used by the OLE DB IDBInitialize::Initialize method, but only for properties that do not have a default value. 如果應用程式在初始化字串中同時使用 ADO 關鍵字和 IDBInitialize::Initialize 關鍵字,將會使用 ADO 關鍵字設定。If an application uses both the ADO keywords and the IDBInitialize::Initialize keywords in the initialization string, the ADO keyword setting will be used. 強烈建議您只讓應用程式使用 ADO 連接字串關鍵字。It is strongly recommended that applications only use ADO connection string keywords.

ADO 使用的連接字串具有以下語法:Connection strings used by ADO have the following syntax:

connection-string ::= empty-string[;] | attribute[;] | attribute; connection-string

empty-string ::=

attribute ::= attribute-keyword=["]attribute-value["]

attribute-value ::= character-string

attribute-keyword ::= identifier

可以選擇用雙引號括住屬性值,這樣是很好的作法。Attribute values can optionally be enclosed in double quotes, and it is good practice to do so. 如此可在值包含非英數字元時避免問題發生。This avoids problems when values contain non-alphanumeric characters. 屬性值不能包含雙引號。Attribute values cannot contain double quotes.

下表描述可搭配 ADO 連接字串使用的關鍵字:The following table describes the keywords that may be used with an ADO connection string:

關鍵字Keyword 初始化屬性Initialization property 說明Description
Application IntentApplication Intent SSPROP_INIT_APPLICATIONINTENTSSPROP_INIT_APPLICATIONINTENT 宣告連接到伺服器時的應用程式工作負載類型。Declares the application workload type when connecting to a server. 可能的值為 ReadOnlyReadWritePossible values are ReadOnly and ReadWrite.

預設值為ReadWriteThe default is ReadWrite. 如需 SQL ServerSQL Server Native Client 支援 AlwaysOn 可用性群組Always On availability groups的詳細資訊,請參閱高可用性和嚴重損壞修復的 SQL Server Native Client 支援For more information about SQL ServerSQL Server Native Client's support for AlwaysOn 可用性群組Always On availability groups, see SQL Server Native Client Support for High Availability, Disaster Recovery.
應用程式名稱Application Name SSPROP_INIT_APPNAMESSPROP_INIT_APPNAME 識別應用程式的字串。The string identifying the application.
自動轉譯Auto Translate SSPROP_INIT_AUTOTRANSLATESSPROP_INIT_AUTOTRANSLATE "AutoTranslate" 的同義字。Synonym for "AutoTranslate".
AutoTranslateAutoTranslate SSPROP_INIT_AUTOTRANSLATESSPROP_INIT_AUTOTRANSLATE 設定 OEM/ANSI 字元轉譯。Configures OEM/ANSI character translation. 認得的值為 "true" 和 "false"。Recognized values are "true" and "false".
連接逾時Connect Timeout DBPROP_INIT_TIMEOUTDBPROP_INIT_TIMEOUT 等候資料來源初始化完成的時間量 (以秒為單位)。The amount of time (in seconds) to wait for data source initialization to complete.
Current LanguageCurrent Language SSPROPT_INIT_CURRENTLANGUAGESSPROPT_INIT_CURRENTLANGUAGE SQL ServerSQL Server 語言名稱。The SQL ServerSQL Server language name.
資料來源Data Source DBPROP_INIT_DATASOURCEDBPROP_INIT_DATASOURCE 組織中 SQL ServerSQL Server 執行個體的名稱。The name of an instance of SQL ServerSQL Server in the organization.

如果沒有指定,就會連接至本機電腦上的預設執行個體。When not specified, a connection is made to the default instance on the local computer.

如需有關有效位址語法的詳細資訊,請參閱本主題中的Server ODBC 關鍵字的說明。For more information about valid address syntax, see the description of the Server ODBC keyword, in this topic.
DataTypeCompatibilityDataTypeCompatibility SSPROP_INIT_DATATYPECOMPATIBILITYSSPROP_INIT_DATATYPECOMPATIBILITY 指定即將使用之資料類型處理的模式。Specifies the mode of data type handling that will be used. 認得的值為 "0" (代表提供者資料類型) 和 "80" (代表 SQL Server 2000 資料類型)。Recognized values are "0" for provider data types and "80" for SQL Server 2000 data types.
Failover PartnerFailover Partner SSPROP_INIT_FAILOVERPARTNERSSPROP_INIT_FAILOVERPARTNER 用於資料庫鏡像的容錯移轉伺服器名稱。The name of the failover server used for database mirroring.
Failover Partner SPNFailover Partner SPN SSPROP_INIT_FAILOVERPARTNERSPNSSPROP_INIT_FAILOVERPARTNERSPN 容錯移轉夥伴的 SPN。The SPN for the failover partner. 預設值為空字串。The default value is an empty string. 空字串會讓 SQL ServerSQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes SQL ServerSQL Server Native Client to use the default, provider-generated SPN.
初始目錄Initial Catalog DBPROP_INIT_CATALOGDBPROP_INIT_CATALOG 資料庫名稱。The database name.
初始檔案名稱Initial File Name SSPROP_INIT_FILENAMESSPROP_INIT_FILENAME 可附加資料庫的主要檔案名稱,包括完整路徑名稱。The name of the primary file (include the full path name) of an attachable database. 若要使用 AttachDBFileName,您還必須使用提供者字串 DATABASE 關鍵字來指定資料庫名稱。To use AttachDBFileName, you must also specify the database name with the provider string DATABASE keyword. 如果之前已附加資料庫,SQL ServerSQL Server 不會重新附加它 (它會使用附加的資料庫當做連接的預設值)。If the database was previously attached, SQL ServerSQL Server does not reattach it (it uses the attached database as the default for the connection).
整合式安全性Integrated Security DBPROP_AUTH_INTEGRATEDDBPROP_AUTH_INTEGRATED 接受 "SSPI" 值進行 Windows 驗證。Accepts the value "SSPI" for Windows Authentication.
MARS ConnectionMARS Connection SSPROP_INIT_MARSCONNECTIONSSPROP_INIT_MARSCONNECTION 當伺服器為 SQL Server 2005 (9.x)SQL Server 2005 (9.x) 或更新版本時,啟用或停用連接上的 Multiple Active Result Sets (MARS)。Enables or disables multiple active result sets (MARS) on the connection if the server is SQL Server 2005 (9.x)SQL Server 2005 (9.x) or later. 認得的值為 "true" 和 "false"。預設值是 "false"。Recognized values are "true" and "false".The default is "false".
Network AddressNetwork Address SSPROP_INIT_NETWORKADDRESSSSPROP_INIT_NETWORKADDRESS 組織中 SQL ServerSQL Server 執行個體的網路位址。The network address of an instance of SQL ServerSQL Server in the organization.

如需有關有效位址語法的詳細資訊,請參閱本主題中的address ODBC 關鍵字的說明。For more information about valid address syntax, see the description of the Address ODBC keyword, in this topic.
Network LibraryNetwork Library SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY 用來建立組織中 SQL ServerSQL Server 執行個體之連接的網路程式庫。The network library used to establish a connection to an instance of SQL ServerSQL Server in the organization.
封包大小Packet Size SSPROP_INIT_PACKETSIZESSPROP_INIT_PACKETSIZE 網路封包大小。Network packet size. 預設值是 4096。The default is 4096.
密碼Password DBPROP_AUTH_PASSWORDDBPROP_AUTH_PASSWORD SQL ServerSQL Server 登入密碼。The SQL ServerSQL Server login password.
保存安全性資訊Persist Security Info DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFODBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO 接受的值為 "true" 和 "false" 字串。Accepts the strings "true" and "false" as values. 如果為 "false",表示不允許資料來源物件保存機密的驗證資訊。When "false" the data source object is not allowed to persist sensitive authentication information.
提供者Provider 如果是 SQL ServerSQL Server Native Client,這應該是 "SQLNCLI11"。For SQL ServerSQL Server Native Client, this should be "SQLNCLI11".
Server SPNServer SPN SSPROP_INIT_SERVERSPNSSPROP_INIT_SERVERSPN 伺服器的 SPN。The SPN for the server. 預設值為空字串。The default value is an empty string. 空字串會讓 SQL ServerSQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes SQL ServerSQL Server Native Client to use the default, provider-generated SPN.
信任伺服器憑證Trust Server Certificate SSPROP_INIT_TRUST_SERVER_CERTIFICATESSPROP_INIT_TRUST_SERVER_CERTIFICATE 接受的值為 "true" 和 "false" 字串。Accepts the strings "true" and "false" as values. 預設值為 "false",這表示將會驗證伺服器憑證。The default value is "false", which means that the server certificate will be validated.
使用加密資料Use Encryption for Data SSPROP_INIT_ENCRYPTSSPROP_INIT_ENCRYPT 指定當透過網路傳送資料以前,是否應該先加密資料。Specifies whether data should be encrypted before sending it over the network. 可能的值為 "true" 和 "false"。Possible values are "true" and "false". 預設值為 "false"。The default value is "false".
使用者識別碼User ID DBPROP_AUTH_USERIDDBPROP_AUTH_USERID SQL ServerSQL Server 登入名稱。The SQL ServerSQL Server login name.
Workstation IDWorkstation ID SSPROP_INIT_WSIDSSPROP_INIT_WSID 工作站識別碼。The workstation identifier.

請注意:在此連接字串中,"Old Password" 屬性會設定 SSPROP_AUTH_OLD_PASSWORD,這是無法透過提供者字串屬性取得的目前密碼 (可能已過期)。Note In the connection string, the "Old Password" property sets SSPROP_AUTH_OLD_PASSWORD, which is the current (possibly expired) password that is not available via a provider string property.

另請參閱See also

使用 SQL Server Native Client 建立應用程式Building Applications with SQL Server Native Client