ConnectionString 属性 (ADO)ConnectionString Property (ADO)

指示用于建立与数据源的连接的信息。Indicates the information used to establish a connection to a data source.

设置和返回值Settings and Return Values

设置或返回一个 字符串 值。Sets or returns a String value.

注解Remarks

使用 ConnectionString 属性来指定数据源,方法是传递包含一系列由分号分隔的 参数 = 值 语句的详细连接字符串。Use the ConnectionString property to specify a data source by passing a detailed connection string containing a series of argument = value statements separated by semicolons.

ADO 支持 ConnectionString 属性的五个参数;任何其他参数将直接传递给提供程序,而无需 ADO 处理。ADO supports five arguments for the ConnectionString property; any other arguments pass directly to the provider without any processing by ADO. ADO 支持的参数如下所示。The arguments ADO supports are as follows.

参数Argument 说明Description
Provider =Provider= 指定要用于连接的访问接口的名称。Specifies the name of a provider to use for the connection.
文件名 =File Name= 指定特定于提供程序的文件的名称 (例如,保留的数据源对象) 包含预设的连接信息。Specifies the name of a provider-specific file (for example, a persisted data source object) containing preset connection information.
远程提供程序 =Remote Provider= 指定打开客户端连接时要使用的提供程序的名称。Specifies the name of a provider to use when opening a client-side connection. 仅 (远程数据服务。 ) (Remote Data Service only.)
远程服务器 =Remote Server= 指定打开客户端连接时要使用的服务器的路径名称。Specifies the path name of the server to use when opening a client-side connection. 仅 (远程数据服务。 ) (Remote Data Service only.)
URL =URL= 将连接字符串指定为标识资源的绝对 URL,如文件或目录。Specifies the connection string as an absolute URL identifying a resource, such as a file or directory.

设置 ConnectionString 属性并打开 连接 对象后,提供程序可以更改属性的内容,例如,通过将 ADO 定义的参数名称映射到特定提供程序的等效项。After you set the ConnectionString property and open the Connection object, the provider may alter the contents of the property, for example, by mapping the ADO-defined argument names to their equivalents for the specific provider.

ConnectionString属性会自动继承用于Open方法的connectionstring参数的值,因此,您可以在打开方法调用过程中重写当前的ConnectionString属性。The ConnectionString property automatically inherits the value used for the ConnectionString argument of the Open method, so you can override the current ConnectionString property during the Open method call.

由于 文件名 参数会使 ADO 加载关联的提供程序,因此不能同时传递 ProviderFile Name 参数。Because the File Name argument causes ADO to load the associated provider, you cannot pass both the Provider and File Name arguments.

连接关闭时, ConnectionString 属性是可读/写的,当连接处于打开状态时为只读。The ConnectionString property is read/write when the connection is closed and read-only when it is open.

ConnectionString属性中参数的重复项将被忽略。Duplicates of an argument in the ConnectionString property are ignored. 使用任何自变量的最后一个实例。The last instance of any argument is used.

备注

远程数据服务使用情况 当用于客户端 连接 对象时, ConnectionString 属性只能包括 远程提供程序远程服务器 参数。Remote Data Service Usage When used on a client-side Connection object, the ConnectionString property can include only the Remote Provider and Remote Server parameters.

下表列出了每个 Windows 操作系统的默认 ADO 提供程序:The following table lists the default ADO provider for each Windows operating system:

默认 ADO 提供程序Default ADO provider Windows 操作系统Windows operating system
MSDASQLMSDASQL

(为了提高源代码的可读性,请在连接字符串中显式指定提供程序名称。 ) (To improve the readability of source code, explicitly specify the provider name in the connection string.)
Windows 2000 (32) Windows 2000 (32-bit)

Windows XP(32 位)Windows XP (32-bit)

Windows 2003 Server (32) Windows 2003 Server (32-bit)

Windows Vista(32 位)Windows Vista (32-bit)

Windows Vista Service Pack 1 或更高版本 (32 位和 64) Windows Vista Service Pack 1 or later (32-bit and 64-bit)

Windows Vista 之后的 windows 版本 (32 位和64位) Windows versions after Windows Vista (32-bit and 64-bit)
无默认设置。No default.

当 ADO 应用程序在以下操作系统上运行且未显式指定提供程序时,ADO 将返回以下错误: "ADODB.RECORDSET"。连接:未指定提供程序,并且没有指定的默认提供程序When an ADO application runs on the following operating systems and does not specify the provider explicitly, ADO returns the following error: "ADODB.Connection: provider is not specified and there is no designated default provider"
Windows 2000 (64) Windows 2000 (64-bit)

Windows XP(64 位)Windows XP (64-bit)

Windows 2003 Server (64) Windows 2003 Server (64-bit)

Windows Vista(64 位)Windows Vista (64-bit)

适用于Applies To

连接对象 (ADO)Connection Object (ADO)

另请参阅See Also

ConnectionString、ConnectionTimeout 和 State 属性示例 (VB) ConnectionString, ConnectionTimeout, and State Properties Example (VB)
ConnectionString、ConnectionTimeout 和 State 属性示例 (VC + +) ConnectionString, ConnectionTimeout, and State Properties Example (VC++)
附录 A:提供程序Appendix A: Providers