将连接字符串关键字用于 SQL Server Native ClientUsing Connection String Keywords with SQL Server Native Client

适用对象:是SQL Server 是Azure SQL 数据库 是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.msi)将保持不推荐使用,不建议用于新的开发工作。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.
有关信息,请参阅将连接字符串关键字与 SQL Server 的 OLE DB 驱动程序配合使用For information, see Using Connection String Keywords with OLE DB Driver for SQL Server.

备注

SQL ServerSQL Server Native Client 允许连接字符串中存在多义性,以保持向后兼容(例如,可以多次指定某些关键字,并且允许基于位置或优先级对发生冲突的关键字进行解析)。SQL ServerSQL 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 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 数据对象 (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 或 named pipes 协议。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:

[protocol:]Address[,port |\pipe\pipename][protocol:]Address[,port |\pipe\pipename]

协议可以是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 将使用 Configuration Manager 中SQL ServerSQL Server指定的协议顺序。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 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.
应用APP 调用SQLDriverConnect的应用程序的名称(可选)。Name of the application calling SQLDriverConnect (optional). 如果指定此值,此值将存储在sysprocessesprogram_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. 可能的值为 ReadOnly 和 ReadWrite********。Possible values are ReadOnly and ReadWrite. 默认值为ReadWriteThe default is ReadWrite. 例如:For example:

ApplicationIntent=ReadOnly

有关SQL ServerSQL Server Native Client 对Always On 可用性组Always On availability groups的支持的详细信息,请参阅对高可用性和灾难恢复的 SQL Server Native Client 支持For more information about SQL ServerSQL Server Native Client's support for Always On 可用性组Always On availability groups, 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.

使用客户端 ANSI 代码页SQL ServerSQL Server (ACP)将发送到CHARvarchartext变量、参数或列的客户端 SQL_C_CHAR 数据从字符转换为 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 ServerSQL Server使用服务器 ACP 将发送到客户端 SQL_C_CHAR 变量的charvarchartext数据从字符转换为 UNICODE,然后使用客户端 ACP 将 unicode 转换为字符。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 server 数据。* 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.

Native Client ODBC 驱动程序不会将客户端 ANSI 字符转换 SQL_C_CHAR 发送到服务器上的CHARvarchar或 text 变量、参数或列的数据。 **** SQL ServerSQL ServerThe 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.
DatabaseDatabase 连接的默认 SQL ServerSQL Server 数据库的名称。Name of the default SQL ServerSQL 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 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.
加密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".
后退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 语言名称(可选)。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 启用或禁用连接上的多个活动结果集 (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. 默认值为“否”****。The default is No. 例如:For example:

MultiSubnetFailover=Yes

有关SQL ServerSQL Server Native Client 对Always On 可用性组Always On availability groups的支持的详细信息,请参阅对高可用性和灾难恢复的 SQL Server Native Client 支持For more information about SQL ServerSQL Server Native Client's support for Always On 可用性组Always On availability groups, see SQL Server Native Client Support for High Availability, Disaster Recovery.
NetNet “Network”的同义词。Synonym for "Network".
网桥Network 有效值为dbnmpntw (named pipes)和dbmssocn (tcp/ip)。Valid values are dbnmpntw (named pipes) and dbmssocn (TCP/IP).

同时为Network关键字和服务器关键字的协议前缀指定一个值是错误的。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. **** 如果登录名的密码为空或使用 Windows 身份验证(Trusted_Connection = yes),则无需指定 PWD。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 ServerSQL Server 使用关于 SQL 语句中引号方法的 ISO 规则。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 遵循关于 SQL 语句中引号用法的早期 Transact-SQLTransact-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.
区域Regional 如果是“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 =.;Server=.;

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

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

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

**Server = (localdb)\ ** 实例_名称 ;Server=(localdb)\ instancename ;

有关 LocalDB 支持的详细信息,请参阅localdb 的 SQL Server Native Client 支持For more information about LocalDB support, see SQL Server Native Client Support for LocalDB.

若要指定的命名实例SQL ServerSQL Server,请**\**追加_InstanceName。To 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 或 named pipes 协议。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]Server=[protocol:]Server[,port]

协议可以是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

此行指定 named pipes 协议、本地计算机上的一个命名管道 (\\.\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 将使用 Configuration Manager 中SQL ServerSQL Server指定的协议顺序。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 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 工作站 ID。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.

[!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client ODBC 驱动程序使用当前用户的区域设置注册表设置。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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:: Initialize****IDBInitialize::Initialize** - **IDataInitialize:: GetDataSource****IDataInitialize::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. > [!NOTE] > 通过 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. 例如,如果指定连接字符串**Data Source = 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. 将 IDBInitialize::Initialize 和 DBPROP_INIT_PROVIDERSTRING 配合使用的 OLE DB 应用程序所使用的连接字符串具有以下语法\*\*\*\*: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| |-------------|-----------------------------|-----------------| |**Addr****Addr**|SSPROP_INIT_NETWORKADDRESSSSPROP_INIT_NETWORKADDRESS|“Address”的同义词。Synonym for "Address".| |**地址****Address**|SSPROP_INIT_NETWORKADDRESSSSPROP_INIT_NETWORKADDRESS|组织中的 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 实例的网络地址。The network address of an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] in the organization.

有关有效地址语法的详细信息,请参阅本主题后面的 " **address** ODBC 关键字说明"。For more information about valid address syntax, see the description of the **Address** ODBC keyword, later in this topic.| |**应用****APP**|SSPROP_INIT_APPNAMESSPROP_INIT_APPNAME|用于标识应用程序的字符串。The string identifying the application.| |**ApplicationIntent****ApplicationIntent**|SSPROP_INIT_APPLICATIONINTENTSSPROP_INIT_APPLICATIONINTENT|连接到服务器时声明应用程序工作负荷类型。Declares the application workload type when connecting to a server. 可能的值为 ReadOnly 和 ReadWrite\*\*\*\*\*\*\*\*。Possible values are **ReadOnly** and **ReadWrite**.

默认值为**ReadWrite**。The default is **ReadWrite**. 有关[!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client 对[!INCLUDE[ssHADR](../../../includes/sshadr-md.md)]的支持的详细信息,请参阅[对高可用性和灾难恢复的 SQL Server Native Client 支持](../../../relational-databases/native-client/features/sql-server-native-client-support-for-high-availability-disaster-recovery.md)。For more information about [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client's support for [!INCLUDE[ssHADR](../../../includes/sshadr-md.md)], see [SQL Server Native Client Support for High Availability, Disaster Recovery](../../../relational-databases/native-client/features/sql-server-native-client-support-for-high-availability-disaster-recovery.md).| |**AttachDBFileName****AttachDBFileName**|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. 如果该数据库以前已经附加,则 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 不会重新附加它(而是使用已附加的数据库作为连接的默认数据库)。If the database was previously attached, [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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".| |**AutoTranslate****AutoTranslate**|SSPROP_INIT_AUTOTRANSLATESSPROP_INIT_AUTOTRANSLATE|配置 OEM/ANSI 字符转换。Configures OEM/ANSI character translation. 可识别的值为“yes”和“no”。Recognized values are "yes" and "no".| |**Database****Database**|DBPROP_INIT_CATALOGDBPROP_INIT_CATALOG|数据库名称。The database name.| |**DataTypeCompatibility****DataTypeCompatibility**|SSPROP_INIT_DATATYPECOMPATIBILITYSSPROP_INIT_DATATYPECOMPATIBILITY|指定要使用的数据类型的处理模式。Specifies the mode of data type handling to use. 对于访问接口数据类型,可识别的值为“0”,对于 SQL Server 2000 数据类型则为“80”。Recognized values are "0" for provider data types and "80" for SQL Server 2000 data types.| |**加密****Encrypt**|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".| |**FailoverPartner****FailoverPartner**|SSPROP_INIT_FAILOVERPARTNERSSPROP_INIT_FAILOVERPARTNER|用于数据库镜像的故障转移服务器的名称。The name of the failover server used for database mirroring.| |**FailoverPartnerSPN****FailoverPartnerSPN**|SSPROP_INIT_FAILOVERPARTNERSPNSSPROP_INIT_FAILOVERPARTNERSPN|故障转移伙伴的 SPN。The SPN for the failover partner. 默认值为空字符串。The default value is an empty string. 空字符串导致 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client 使用访问接口生成的默认 SPN。An empty string causes [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client to use the default, provider-generated SPN.| |**语言****Language**|SSPROPT_INIT_CURRENTLANGUAGESSPROPT_INIT_CURRENTLANGUAGE| [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 语言。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] language.| |**MarsConn****MarsConn**|SSPROP_INIT_MARSCONNECTIONSSPROP_INIT_MARSCONNECTION|如果服务器是 [!INCLUDE[ssVersion2005](../../../includes/ssversion2005-md.md)] 或更高版本,则启用或禁用连接上的多个活动结果集 (MARS)。Enables or disables multiple active result sets (MARS) on the connection if the server is [!INCLUDE[ssVersion2005](../../../includes/ssversion2005-md.md)] or later. 可能的值为“yes”和“no”。Possible values are "yes" and "no". 默认值为“no”。The default value is "no".| |**Net****Net**|SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY|“Network”的同义词。Synonym for "Network".| |**网桥****Network**|SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY|用于与组织中的 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 实例建立连接的网络库。The network library used to establish a connection to an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] in the organization.| |**网络库****Network Library**|SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY|“Network”的同义词。Synonym for "Network".| |**PacketSize****PacketSize**|SSPROP_INIT_PACKETSIZESSPROP_INIT_PACKETSIZE|网络数据包大小。Network packet size. 默认值为 4096。The default is 4096.| |**PersistSensitive****PersistSensitive**|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| |**PWD****PWD**|DBPROP_AUTH_PASSWORDDBPROP_AUTH_PASSWORD| [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 登录密码。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] login password.| |**Server****Server**|DBPROP_INIT_DATASOURCEDBPROP_INIT_DATASOURCE|组织中的 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 实例的名称。The name of an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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.| |**ServerSPN****ServerSPN**|SSPROP_INIT_SERVERSPNSSPROP_INIT_SERVERSPN|服务器的 SPN。The SPN for the server. 默认值为空字符串。The default value is an empty string. 空字符串导致 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client 使用访问接口生成的默认 SPN。An empty string causes [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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_Connection****Trusted_Connection**|DBPROP_AUTH_INTEGRATEDDBPROP_AUTH_INTEGRATED|如果是“yes”,则指示 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client OLE DB 访问接口使用 Windows 身份验证模式进行登录验证。When "yes", instructs the [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client OLE DB provider to use Windows Authentication Mode for login validation. 否则指示 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client OLE DB 访问接口使用 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 用户名和密码进行登录验证,并且必须指定 UID 和 PWD 关键字。Otherwise instructs the [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client OLE DB provider to use a [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] username and password for login validation, and the UID and PWD keywords must be specified.| |**TrustServerCertificate****TrustServerCertificate**|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.| |**UID****UID**|DBPROP_AUTH_USERIDDBPROP_AUTH_USERID| [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 登录名。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] login name.| |**UseProcForPrepare****UseProcForPrepare**|SSPROP_INIT_USEPROCFORPREPSSPROP_INIT_USEPROCFORPREP|不推荐使用该关键字,并且 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client OLE DB 访问接口将忽略其设置。This keyword is deprecated, and its setting is ignored by the [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client OLE DB Provider.| |**WSID****WSID**|SSPROP_INIT_WSIDSSPROP_INIT_WSID|工作站标识符。The workstation identifier.| 使用 IDataInitialize::GetDataSource 的 OLE DB 应用程序所使用的连接字符串有以下语法\*\*\*\*: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**使用大**{}** 括号()引号字符,**应用程序名称**使用单引号(**'**)或双引号(**"**)。 只有字符串属性可以加引号。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 Intent**|SSPROP_INIT_APPLICATIONINTENTSSPROP_INIT_APPLICATIONINTENT|连接到服务器时声明应用程序工作负荷类型。Declares the application workload type when connecting to a server. 可能的值为 ReadOnly 和 ReadWrite\*\*\*\*\*\*\*\*。Possible values are **ReadOnly** and **ReadWrite**.

默认值为**ReadWrite**。The default is **ReadWrite**. 有关[!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client 对[!INCLUDE[ssHADR](../../../includes/sshadr-md.md)]的支持的详细信息,请参阅[对高可用性和灾难恢复的 SQL Server Native Client 支持](../../../relational-databases/native-client/features/sql-server-native-client-support-for-high-availability-disaster-recovery.md)。For more information about [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client's support for [!INCLUDE[ssHADR](../../../includes/sshadr-md.md)], see [SQL Server Native Client Support for High Availability, Disaster Recovery](../../../relational-databases/native-client/features/sql-server-native-client-support-for-high-availability-disaster-recovery.md).| |**自动转换****Auto Translate**|SSPROP_INIT_AUTOTRANSLATESSPROP_INIT_AUTOTRANSLATE|“AutoTranslate”的同义词。Synonym for "AutoTranslate".| |**AutoTranslate****AutoTranslate**|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 Language**|SSPROPT_INIT_CURRENTLANGUAGESSPROPT_INIT_CURRENTLANGUAGE| [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 语言名称。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] language name.| |**数据源****Data Source**|DBPROP_INIT_DATASOURCEDBPROP_INIT_DATASOURCE|组织中的 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 实例的名称。The name of an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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.| |**DataTypeCompatibility****DataTypeCompatibility**|SSPROP_INIT_DATATYPECOMPATIBILITYSSPROP_INIT_DATATYPECOMPATIBILITY|指定要使用的数据类型的处理模式。Specifies the mode of data type handling to use. 可识别的值对访问接口数据类型为“0”,对 [!INCLUDE[ssVersion2000](../../../includes/ssversion2000-md.md)] 数据类型为“80”。Recognized values are "0" for provider data types and "80" for [!INCLUDE[ssVersion2000](../../../includes/ssversion2000-md.md)] data types.| |**故障转移伙伴****Failover Partner**|SSPROP_INIT_FAILOVERPARTNERSSPROP_INIT_FAILOVERPARTNER|用于数据库镜像的故障转移服务器的名称。The name of the failover server used for database mirroring.| |**故障转移伙伴 SPN****Failover Partner SPN**|SSPROP_INIT_FAILOVERPARTNERSPNSSPROP_INIT_FAILOVERPARTNERSPN|故障转移伙伴的 SPN。The SPN for the failover partner. 默认值为空字符串。The default value is an empty string. 空字符串导致 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client 使用访问接口生成的默认 SPN。An empty string causes [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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**,还必须使用 PROVIDER string database 关键字指定数据库名称。To use **AttachDBFileName**, you must also specify the database name with the provider string DATABASE keyword. 如果该数据库以前已经附加,则 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 不会重新附加它(而是使用已附加的数据库作为连接的默认数据库)。If the database was previously attached, [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] does not reattach it (it uses the attached database as the default for the connection).| |**集成安全性****Integrated Security**|DBPROP_AUTH_INTEGRATEDDBPROP_AUTH_INTEGRATED|接受 Windows 身份验证的值“SSPI”。Accepts the value "SSPI" for Windows Authentication.| |**MARS 连接****MARS Connection**|SSPROP_INIT_MARSCONNECTIONSSPROP_INIT_MARSCONNECTION|启用或禁用连接上的多个活动结果集 (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 Address**|SSPROP_INIT_NETWORKADDRESSSSPROP_INIT_NETWORKADDRESS|组织中的 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 实例的网络地址。The network address of an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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 Library**|SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY|用于与组织中的 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 实例建立连接的网络库。The network library used to establish a connection to an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] in the organization.| |**数据包大小****Packet Size**|SSPROP_INIT_PACKETSIZESSPROP_INIT_PACKETSIZE|网络数据包大小。Network packet size. 默认值为 4096。The default is 4096.| |**权限****Password**|DBPROP_AUTH_PASSWORDDBPROP_AUTH_PASSWORD| [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 登录密码。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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**||对于 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client,这应当是“SQLNCLI11”。For [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client, this should be "SQLNCLI11".| |**服务器 SPN****Server SPN**|SSPROP_INIT_SERVERSPNSSPROP_INIT_SERVERSPN|服务器的 SPN。The SPN for the server. 默认值为空字符串。The default value is an empty string. 空字符串导致 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client 使用访问接口生成的默认 SPN。An empty string causes [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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".| |**用户 ID****User ID**|DBPROP_AUTH_USERIDDBPROP_AUTH_USERID| [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 登录名。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] login name.| |**工作站 ID****Workstation ID**|SSPROP_INIT_WSIDSSPROP_INIT_WSID|工作站标识符。The workstation identifier.| **注意**在连接字符串中,"旧密码" 属性设置 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 数据对象 (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 Intent**|SSPROP_INIT_APPLICATIONINTENTSSPROP_INIT_APPLICATIONINTENT|连接到服务器时声明应用程序工作负荷类型。Declares the application workload type when connecting to a server. 可能的值为 ReadOnly 和 ReadWrite\*\*\*\*\*\*\*\*。Possible values are **ReadOnly** and **ReadWrite**.

默认值为**ReadWrite**。The default is **ReadWrite**. 有关[!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client 对[!INCLUDE[ssHADR](../../../includes/sshadr-md.md)]的支持的详细信息,请参阅[对高可用性和灾难恢复的 SQL Server Native Client 支持](../../../relational-databases/native-client/features/sql-server-native-client-support-for-high-availability-disaster-recovery.md)。For more information about [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client's support for [!INCLUDE[ssHADR](../../../includes/sshadr-md.md)], see [SQL Server Native Client Support for High Availability, Disaster Recovery](../../../relational-databases/native-client/features/sql-server-native-client-support-for-high-availability-disaster-recovery.md).| |**应用程序名称****Application Name**|SSPROP_INIT_APPNAMESSPROP_INIT_APPNAME|用于标识应用程序的字符串。The string identifying the application.| |**自动转换****Auto Translate**|SSPROP_INIT_AUTOTRANSLATESSPROP_INIT_AUTOTRANSLATE|“AutoTranslate”的同义词。Synonym for "AutoTranslate".| |**AutoTranslate****AutoTranslate**|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 Language**|SSPROPT_INIT_CURRENTLANGUAGESSPROPT_INIT_CURRENTLANGUAGE| [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 语言名称。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] language name.| |**数据源****Data Source**|DBPROP_INIT_DATASOURCEDBPROP_INIT_DATASOURCE|组织中的 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 实例的名称。The name of an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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.| |**DataTypeCompatibility****DataTypeCompatibility**|SSPROP_INIT_DATATYPECOMPATIBILITYSSPROP_INIT_DATATYPECOMPATIBILITY|指定将使用的数据类型的处理模式。Specifies the mode of data type handling that will be used. 对于访问接口数据类型,可识别的值为“0”,对于 SQL Server 2000 数据类型则为“80”。Recognized values are "0" for provider data types and "80" for SQL Server 2000 data types.| |**故障转移伙伴****Failover Partner**|SSPROP_INIT_FAILOVERPARTNERSSPROP_INIT_FAILOVERPARTNER|用于数据库镜像的故障转移服务器的名称。The name of the failover server used for database mirroring.| |**故障转移伙伴 SPN****Failover Partner SPN**|SSPROP_INIT_FAILOVERPARTNERSPNSSPROP_INIT_FAILOVERPARTNERSPN|故障转移伙伴的 SPN。The SPN for the failover partner. 默认值为空字符串。The default value is an empty string. 空字符串导致 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client 使用访问接口生成的默认 SPN。An empty string causes [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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**,还必须使用 PROVIDER string database 关键字指定数据库名称。To use **AttachDBFileName**, you must also specify the database name with the provider string DATABASE keyword. 如果该数据库以前已经附加,则 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 不会重新附加它(而是使用已附加的数据库作为连接的默认数据库)。If the database was previously attached, [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] does not reattach it (it uses the attached database as the default for the connection).| |**集成安全性****Integrated Security**|DBPROP_AUTH_INTEGRATEDDBPROP_AUTH_INTEGRATED|接受 Windows 身份验证的值“SSPI”。Accepts the value "SSPI" for Windows Authentication.| |**MARS 连接****MARS Connection**|SSPROP_INIT_MARSCONNECTIONSSPROP_INIT_MARSCONNECTION|如果服务器是 [!INCLUDE[ssVersion2005](../../../includes/ssversion2005-md.md)] 或更高版本,则启用或禁用连接上的多个活动结果集 (MARS)。Enables or disables multiple active result sets (MARS) on the connection if the server is [!INCLUDE[ssVersion2005](../../../includes/ssversion2005-md.md)] or later. 可识别的值为“true”和“false”。默认值为“false”。Recognized values are "true" and "false".The default is "false".| |**网络地址****Network Address**|SSPROP_INIT_NETWORKADDRESSSSPROP_INIT_NETWORKADDRESS|组织中的 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 实例的网络地址。The network address of an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] in the organization.

有关有效地址语法的详细信息,请参阅本主题中的**address** ODBC 关键字说明。For more information about valid address syntax, see the description of the **Address** ODBC keyword, in this topic.| |**网络库****Network Library**|SSPROP_INIT_NETWORKLIBRARYSSPROP_INIT_NETWORKLIBRARY|用于与组织中的 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 实例建立连接的网络库。The network library used to establish a connection to an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] in the organization.| |**数据包大小****Packet Size**|SSPROP_INIT_PACKETSIZESSPROP_INIT_PACKETSIZE|网络数据包大小。Network packet size. 默认值为 4096。The default is 4096.| |**权限****Password**|DBPROP_AUTH_PASSWORDDBPROP_AUTH_PASSWORD| [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 登录密码。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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**||对于 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client,这应当是“SQLNCLI11”。For [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client, this should be "SQLNCLI11".| |**服务器 SPN****Server SPN**|SSPROP_INIT_SERVERSPNSSPROP_INIT_SERVERSPN|服务器的 SPN。The SPN for the server. 默认值为空字符串。The default value is an empty string. 空字符串导致 [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Native Client 使用访问接口生成的默认 SPN。An empty string causes [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 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".| |**用户 ID****User ID**|DBPROP_AUTH_USERIDDBPROP_AUTH_USERID| [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] 登录名。The [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] login name.| |**工作站 ID****Workstation ID**|SSPROP_INIT_WSIDSSPROP_INIT_WSID|工作站标识符。The workstation identifier.| **注意**在连接字符串中,"旧密码" 属性设置 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](../../../relational-databases/native-client/applications/building-applications-with-sql-server-native-client.md)