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

本主題適用於: 是SQL Server是Azure SQL Database是Azure SQL 資料倉儲 是平行處理資料倉儲 THIS TOPIC APPLIES TO: yesSQL ServeryesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

某些 [SQL Server]SQL Server Native Client API 會使用連接字串來指定連接屬性。Some [SQL Server]SQL 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 Server]SQL Server Native Client 允許模稜兩可在連接字串,以維護回溯相容性 (例如,某些關鍵字可能會指定一次以上,及位置為基礎的解析可能會允許衝突的關鍵字或優先順序)。NOTE: [SQL Server]SQL Server 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 Server]SQL Server Native Client 版本可能不允許模稜兩可的連接字串。Future releases of [SQL Server]SQL Server Native Client might not allow ambiguity in connection strings. 當修改應用程式,以便使用 [SQL Server]SQL Server Native Client 來移除對於模稜兩可之連接字串的任何相依性時,這就是很好的作法。It is good practice when modifying applications to use [SQL Server]SQL Server Native Client to eliminate any dependency on connection string ambiguity.

下列章節描述當使用 [SQL Server]SQL Server Native Client 當做資料提供者時,可以搭配 [SQL Server]SQL Server Native Client OLE DB 提供者、 [SQL Server]SQL Server Native Client ODBC 驅動程式和 ActiveX Data Objects (ADO) 使用的關鍵字。The following sections describe the keywords that can be used with the [SQL Server]SQL Server Native Client OLE DB provider, the [SQL Server]SQL Server Native Client ODBC driver, and ActiveX Data Objects (ADO) when using [SQL Server]SQL 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 Server]SQL Server 執行個體之伺服器的網路位址。The network address of the server running an instance of [SQL Server]SQL 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 Server]SQL Server 組態管理員中已啟用 TCP/IP 或具名管道通訊協定。If you specify an IP address, make sure that the TCP/IP or named pipes protocols are enabled in [SQL Server]SQL Server Configuration Manager.

地址傳遞給的值中的優先順序高於伺服器時使用的 ODBC 連接字串中 [SQL Server]SQL Server原生用戶端。The value of Address takes precedence over the value passed to Server in ODBC connection strings when using [SQL Server]SQL 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). 如需有關通訊協定的詳細資訊,請參閱Configure Client ProtocolsFor more information about protocols, see Configure Client Protocols.

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

port 是在指定伺服器上所要連接的通訊埠。port is the port to connect to, on the specified server. 根據預設, [SQL Server]SQL Server 會使用通訊埠 1433。By default, [SQL Server]SQL 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). 如果指定,這個值會儲存在master.dbo.sysprocesses資料行sys.sysprocesses ,傳回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 Server]SQL ServerNative Client 支援 AlwaysOn 可用性群組Always On availability groups,請參閱SQL Server 原生用戶端支援高可用性、 災害復原For more information about [SQL Server]SQL 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 DATABASE 參數或 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 Server]SQL Server 不會重新附加它,它會使用附加的資料庫當做連接的預設值。If the database was previously attached, [SQL Server]SQL 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_C_CHAR 資料傳送至 [SQL Server]SQL Server charvarchar,或文字變數、 參數或資料行從轉換的字元為使用用戶端的 Unicode此外,ANSI 字碼頁 (ACP),然後會從 Unicode 轉換成字元使用伺服器的 ACP 轉換。Client SQL_C_CHAR data sent to a [SQL Server]SQL 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 Server]SQL Server charvarchar,或文字傳送到用戶端的 SQL_C_CHAR 變數的資料是從字元轉換成 Unicode 使用伺服器的 ACP,則從 Unicode 轉換成字元使用用戶端轉換ACP。 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 Server]SQL Server Native Client ODBC 驅動程式在用戶端上執行。These conversions are performed on the client by the [SQL Server]SQL 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 用戶端資料傳送至charvarchar,或文字伺服器上。* Unicode SQL_C_WCHAR client data sent to char, varchar, or text on the server.

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

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

* Unicode ncharnvarchar,或ntext伺服器資料傳送到用戶端上之 ANSI SQL_C_CHAR 變數。* 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 Server]SQL Server Native Client ODBC 驅動程式不會轉譯傳送到用戶端 ANSI 字元 SQL_C_CHAR 資料charvarchar,或文字變數、 參數,或在伺服器上的資料行。The [SQL Server]SQL 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. 上執行任何轉譯charvarchar,或文字從伺服器傳送至用戶端的 SQL_C_CHAR 變數的資料。No translation is performed on char, varchar, or text data sent from the server to SQL_C_CHAR variables on the client.

如果用戶端和 [SQL Server]SQL Server 使用不同的 ACP,可能會將擴充字元解譯錯誤。If the client and [SQL Server]SQL Server are using different ACPs, extended characters may be misinterpreted.
[資料庫備份]Database 用於連接的預設 [SQL Server]SQL Server 資料庫名稱。Name of the default [SQL Server]SQL Server database for the connection. 如果資料庫未指定,會使用定義的登入的預設資料庫。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 所傳回的驅動程式名稱SQLDriversName of the driver as returned by SQLDrivers. [SQL Server]SQL Server Native Client ODBC 驅動程式的關鍵字值是 "{SQL Server Native Client 11.0}"。The keyword value for the [SQL Server]SQL Server Native Client ODBC driver is "{SQL Server Native Client 11.0}". 伺服器關鍵字是必要的如果驅動程式指定並DriverCompletion設定為 SQL_DRIVER_NOPROMPT。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 Server]SQL Server Native Client ODBC 驅動程式會忽略它的設定。This keyword is deprecated, and its setting is ignored by the [SQL Server]SQL 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 Server]SQL Server Native Client 使用驅動程式產生的預設 SPN。An empty string causes [SQL Server]SQL Server Native Client to use the default, driver-generated SPN.
FileDSNFileDSN 現有 ODBC 檔案資料來源的名稱。Name of an existing ODBC file data source.
語言Language [SQL Server]SQL Server 語言名稱 (選擇性)。 language name (optional). [SQL Server]SQL Server 可以儲存多種語言的訊息sysmessages can store messages for multiple languages in sysmessages. 如果連接到 [SQL Server]SQL Server多種語言,與語言指定哪些訊息組合用來連線。If connecting to a [SQL Server]SQL 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 一律指定multiSubnetFailover = Yes連接到可用性群組接聽程式時 [SQL Server]SQL Server可用性群組或 [SQL Server]SQL Server容錯移轉叢集執行個體。Always specify multiSubnetFailover=Yes when connecting to the availability group listener of a [SQL Server]SQL Server availability group or a [SQL Server]SQL Server Failover Cluster Instance. multiSubnetFailover = Yes會設定 [SQL Server]SQL ServerNative Client 來提供更快速的偵測與連接 (目前) 作用中的伺服器。multiSubnetFailover=Yes configures [SQL Server]SQL 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 Server]SQL ServerNative Client 支援 AlwaysOn 可用性群組Always On availability groups,請參閱SQL Server 原生用戶端支援高可用性、 災害復原For more information about [SQL Server]SQL 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).

它會指定這兩個值的錯誤網路關鍵字和通訊協定前置詞上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 Server]SQL Server 登入帳戶的密碼。The password for the [SQL Server]SQL Server login account specified in the UID parameter. PWD不需要指定如果登入具有 NULL 密碼或使用 Windows 驗證 (Trusted_Connection = yes)。PWD 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 Server]SQL Server 會使用 ISO 規則,不論 SQL 陳述式中是否使用引號。When "yes", QUOTED_IDENTIFIERS is set ON for the connection, [SQL Server]SQL 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 Server]SQL Server 會遵循 Transact-SQLTransact-SQL 傳統規則,不論 SQL 陳述式中是否使用引號。 [SQL Server]SQL 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.
地區Regional 當設定為 "yes" 時, [SQL Server]SQL Server Native Client ODBC 驅動程式將貨幣、日期和時間資料轉換成字元資料時,會使用用戶端設定。When "yes", the [SQL Server]SQL 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 Server]SQL Server 執行個體的名稱。The name of a [SQL Server]SQL Server instance. 此值必須是網路上的伺服器名稱、IP 位址,或是 [SQL Server]SQL Server 組態管理員別名的名稱。The value must be either the name of a server on the network, an IP address, or the name of a [SQL Server]SQL Server Configuration Manager alias.

地址關鍵字會覆寫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=;

Server=.;Server=.;

Server=(local);Server=(local);

Server=(local);Server=(local);

Server=(localhost);Server=(localhost);

Server=(localdb)\ instancename ;Server=(localdb)\ instancename ;

如需有關 LocalDB 支援的詳細資訊,請參閱 < SQL Server Native Client 支援 localdbFor more information about LocalDB support, see SQL Server Native Client Support for LocalDB.

若要指定的具名執行個體 [SQL Server]SQL Server,附加 \ ***InstanceName *。

如果未不指定任何伺服器,會連接到本機電腦上預設執行個體。

如果您指定的 IP 位址,請確定在已啟用 TCP/IP 或具名的管道通訊協定 [SQL Server]SQL ServerConfiguration Manager。

完整語法
伺服器關鍵字如下:

**Server =
[* 通訊協定:]伺服器*[、 * * * 連接埠]
To specify a named instance of [SQL Server]SQL Server, append **\InstanceName *.

When no server is specified, a connection is made to the default instance on the local computer.

If you specify an IP address, make sure that the TCP/IP or named pipes protocols are enabled in [SQL Server]SQL Server Configuration Manager.

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 Server]SQL Server 執行個體的名稱 (MSSQL$MYINST01) 以及具名管道的預設名稱 (sql/query)。This line specifies named pipe protocol, a named pipe on the local machine (\\.\pipe), the name of the [SQL Server]SQL Server instance (MSSQL$MYINST01), and the default name of the named pipe (sql/query).

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

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

傳遞給的值開頭的空格會被忽略伺服器時使用的 ODBC 連接字串中 [SQL Server]SQL Server原生用戶端。Spaces are ignored at the beginning of the value passed to Server in ODBC connection strings when using [SQL Server]SQL Server Native Client.
ServerSPNServerSPN 伺服器的 SPN。The SPN for the server. 預設值為空字串。The default value is an empty string. 空字串會讓 [SQL Server]SQL Server Native Client 使用驅動程式產生的預設 SPN。An empty string causes [SQL Server]SQL Server Native Client to use the default, driver-generated SPN.
StatsLog_OnStatsLog_On 當設定為 "yes" 時,會啟用 [SQL Server]SQL Server Native Client ODBC 驅動程式效能資料的擷取。When "yes", enables the capture of [SQL Server]SQL Server Native Client ODBC driver performance data. 當設定為 "no" 時,連接上無法取得 [SQL Server]SQL Server Native Client ODBC 驅動程式效能資料。When "no", [SQL Server]SQL Server Native Client ODBC driver performance data is not available on the connection.
StatsLogFileStatsLogFile 用來記錄 [SQL Server]SQL Server Native Client ODBC 驅動程式效能統計資料之檔案的完整路徑和檔案名稱。Full path and file name of a file used to record [SQL Server]SQL Server Native Client ODBC driver performance statistics.
Trusted_ConnectionTrusted_Connection 當為 "yes" 時,會指示 [SQL Server]SQL Server Native Client ODBC 驅動程式使用 Windows 驗證模式進行登入驗證。When "yes", instructs the [SQL Server]SQL Server Native Client ODBC driver to use Windows Authentication Mode for login validation. 否則會指示 [SQL Server]SQL Server Native Client ODBC 驅動程式使用 [SQL Server]SQL Server 使用者名稱和密碼進行登入驗證,而且必須指定 UID 和 PWD 密碼。Otherwise instructs the [SQL Server]SQL Server Native Client ODBC driver to use a [SQL Server]SQL Server username and password for login validation, and the UID and PWD keywords must be specified.
TrustServerCertificateTrustServerCertificate 當搭配Encrypt,可讓使用自我簽署的伺服器憑證加密。When used with Encrypt, enables encryption using a self-signed server certificate.
UIDUID 有效的 [SQL Server]SQL Server 登入帳戶。A valid [SQL Server]SQL Server login account. 使用 Windows 驗證時不需要指定 UID。UID need not be specified when using Windows Authentication.
UseProcForPrepareUseProcForPrepare 這個關鍵字已被取代,而且 [SQL Server]SQL Server Native Client ODBC 驅動程式會忽略它的設定。This keyword is deprecated, and its setting is ignored by the [SQL Server]SQL Server Native Client ODBC Driver.
WSIDWSID 工作站識別碼。The workstation ID. 一般而言,這是應用程式所在之電腦的網路名稱 (選擇性)。Typically, this is the network name of the computer on which the application resides (optional). 如果指定,這個值會儲存在master.dbo.sysprocesses資料行hostname ,傳回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 Server]SQL Server Native Client ODBC 驅動程式會針對目前的使用者使用地區設定的登錄設定。The [SQL Server]SQL Server Native Client ODBC driver uses the locale registry settings for the current user. 驅動程式不會接受目前的執行緒地區設定,如果應用程式設定它之後連接,例如,呼叫SetThreadLocaleThe 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資料來源會設定為屬性,但Server將會進入提供者字串。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 Server]SQL Server 執行個體的網路位址。The network address of an instance of [SQL Server]SQL Server in the organization.

如需有關有效位址語法的詳細資訊,請參閱說明地址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 Server]SQL ServerNative Client 支援 AlwaysOn 可用性群組Always On availability groups,請參閱SQL Server 原生用戶端支援高可用性、 災害復原For more information about [SQL Server]SQL 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 Server]SQL Server 不會重新附加它 (它會使用附加的資料庫當做連接的預設值)。If the database was previously attached, [SQL Server]SQL 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 Server]SQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes [SQL Server]SQL Server Native Client to use the default, provider-generated SPN.
語言Language SSPROPT_INIT_CURRENTLANGUAGESSPROPT_INIT_CURRENTLANGUAGE [SQL Server]SQL Server 語言。The [SQL Server]SQL Server language.
MarsConnMarsConn SSPROP_INIT_MARSCONNECTIONSSPROP_INIT_MARSCONNECTION 當伺服器為 SQL Server 2005SQL Server 2005 或更新版本時,啟用或停用連接上的 Multiple Active Result Sets (MARS)。Enables or disables multiple active result sets (MARS) on the connection if the server is SQL Server 2005SQL Server 2005 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 Server]SQL Server 執行個體之連接的網路程式庫。The network library used to establish a connection to an instance of [SQL Server]SQL 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 Server]SQL Server 登入密碼。The [SQL Server]SQL Server login password.
ServerServer DBPROP_INIT_DATASOURCEDBPROP_INIT_DATASOURCE 組織中 [SQL Server]SQL Server 執行個體的名稱。The name of an instance of [SQL Server]SQL 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 Server]SQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes [SQL Server]SQL 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 Server]SQL Server Native Client OLE DB 提供者使用 Windows 驗證模式進行登入驗證。When "yes", instructs the [SQL Server]SQL Server Native Client OLE DB provider to use Windows Authentication Mode for login validation. 否則會指示 [SQL Server]SQL Server Native Client OLE DB 提供者使用 [SQL Server]SQL Server 使用者名稱和密碼進行登入驗證,而且必須指定 UID 和 PWD 密碼。Otherwise instructs the [SQL Server]SQL Server Native Client OLE DB provider to use a [SQL Server]SQL 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 Server]SQL Server 登入名稱。The [SQL Server]SQL Server login name.
UseProcForPrepareUseProcForPrepare SSPROP_INIT_USEPROCFORPREPSSPROP_INIT_USEPROCFORPREP 這個關鍵字已被取代,而且 [SQL Server]SQL Server Native Client OLE DB 提供者會忽略它的設定。This keyword is deprecated, and its setting is ignored by the [SQL Server]SQL 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 NameApplication 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 Server]SQL ServerNative Client 支援 AlwaysOn 可用性群組Always On availability groups,請參閱SQL Server 原生用戶端支援高可用性、 災害復原For more information about [SQL Server]SQL 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 Server]SQL Server 語言名稱。The [SQL Server]SQL Server language name.
資料來源Data Source DBPROP_INIT_DATASOURCEDBPROP_INIT_DATASOURCE 組織中 [SQL Server]SQL Server 執行個體的名稱。The name of an instance of [SQL Server]SQL 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 Server]SQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes [SQL Server]SQL 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 Server]SQL Server 不會重新附加它 (它會使用附加的資料庫當做連接的預設值)。If the database was previously attached, [SQL Server]SQL 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 Server]SQL Server 執行個體的網路位址。The network address of an instance of [SQL Server]SQL Server in the organization.

如需有關有效位址語法的詳細資訊,請參閱說明地址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 Server]SQL Server 執行個體之連接的網路程式庫。The network library used to establish a connection to an instance of [SQL Server]SQL 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 Server]SQL Server 登入密碼。The [SQL Server]SQL 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 Server]SQL Server Native Client,這應該是 "SQLNCLI11"。For [SQL Server]SQL 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 Server]SQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes [SQL Server]SQL 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 Server]SQL Server 登入名稱。The [SQL Server]SQL 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 Server]SQL ServerNative Client 支援 AlwaysOn 可用性群組Always On availability groups,請參閱SQL Server 原生用戶端支援高可用性、 災害復原For more information about [SQL Server]SQL Server Native Client's support for AlwaysOn 可用性群組Always On availability groups, see SQL Server Native Client Support for High Availability, Disaster Recovery.
Application NameApplication 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 Server]SQL Server 語言名稱。The [SQL Server]SQL Server language name.
資料來源Data Source DBPROP_INIT_DATASOURCEDBPROP_INIT_DATASOURCE 組織中 [SQL Server]SQL Server 執行個體的名稱。The name of an instance of [SQL Server]SQL 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 Server]SQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes [SQL Server]SQL 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 Server]SQL Server 不會重新附加它 (它會使用附加的資料庫當做連接的預設值)。If the database was previously attached, [SQL Server]SQL 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 2005SQL Server 2005 或更新版本時,啟用或停用連接上的 Multiple Active Result Sets (MARS)。Enables or disables multiple active result sets (MARS) on the connection if the server is SQL Server 2005SQL Server 2005 or later. 認得的值為 "true" 和 "false"。預設值是 "false"。Recognized values are "true" and "false".The default is "false".
Network AddressNetwork Address SSPROP_INIT_NETWORKADDRESSSSPROP_INIT_NETWORKADDRESS 組織中 [SQL Server]SQL Server 執行個體的網路位址。The network address of an instance of [SQL Server]SQL Server in the organization.

如需有關有效位址語法的詳細資訊,請參閱說明地址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 Server]SQL Server 執行個體之連接的網路程式庫。The network library used to establish a connection to an instance of [SQL Server]SQL 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 Server]SQL Server 登入密碼。The [SQL Server]SQL 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 Server]SQL Server Native Client,這應該是 "SQLNCLI11"。For [SQL Server]SQL 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 Server]SQL Server Native Client 使用提供者產生的預設 SPN。An empty string causes [SQL Server]SQL 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 Server]SQL Server 登入名稱。The [SQL Server]SQL 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