ConnectionString Property - ADO

在开发学生信息系统时,遇到Access数据库有密码无法连接的问题。通过ConnectionString属性设置数据库连接,但添加password属性后仍提示错误。查阅MSDN发现ConnectionString用于指定数据源,由一系列参数组成。ADO支持7个参数,如Provider、FileName等,但不能同时设置Provider和FileName。ConnectionString在连接关闭时可读写,打开时只读。远程数据服务下,客户端ConnectionString仅包含Remote Provider和Remote Server参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天进行一个学生信息系统的查询开发时,发现老师给的数据库(Access)有密码,不知道怎么连接了,在通常的数据连接中,我添加了password属性后,提示说我的密码错误,无法连接,刷新了一下后提示说:“文件正在使用或其他的程序以独占的方式打开了”,怎么办,以前没有遇到过此类问题啊!傻了,那就看看MSDN 的帮助,以下是查询的connectionString的说明,简单的翻译以下(红色的部分翻译得不好,希望大家帮忙看看)。

ConnectionString Property - ADO

Contains the information used to establish a connection to a data source.

提供给connection的数据库连接的信息,返回值为一个字符串

Applies To

Connection

Settings and Return Values

Sets or returns a String value.

Remarks

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.

使用ConnectionStrin属性的一系列的“argument = value”的参数连接到一个特定的数据库,连接的参数采用“;”隔离。ADO为ConnectionStrin提供7个连接参数,其他的参数直接由提供者而不是ADO。ADO支持的参数如下:

ADO supports seven arguments for the ConnectionString property; any other arguments pass directly to the provider without any processing by ADO. The arguments ADO supports are as follows:

Argument

Description

 

 

Provider=

Specifies the name of a provider to use for the connection.

Data Source=

Specifies the name of a data source for the connection, for example, a SQL Server database registered as an ODBC data source.

User ID=

Specifies the user name to use when opening the connection.

Password=

Specifies the password to use when opening 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 sever to use when opening a client-side connection. (Remote Data Service only.)

参数

描述

 

 

Provider=

指定连接的提供者

Data Source=

指定连接的数据源。比如:一个SQL服务器数据库被注册为ODBC数据源。

User ID=

打开数据库用户名

Password=

打开数据库的密码

File Name=

Specifies the name of a provider-specific file (for example, a persisted data source object) containing preset connection information.

指定提供者的特定的文件名(例如:一个XX的数据库对象),该文件包含连接信息

Remote Provider=

当打开一个客户端连接时,指定一个服务提供名(仅使用于远程数据库)

Remote Server=

当打开一个客户端连接时,指定服务器的名称(仅使用于远程数据库)

 

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 provider equivalents.

当打开Connection对象,并为其设置了ConnectionString对象时,提供者将显示属性的内容。比如:通过影射ADO定义参数,命名提供者的对象。

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.

通过Open方法,ConnectionString能自动的插入参数值,所以通过调用Open方法可以重载当前的ConnectionString属性。

Because the File Name argument causes ADO to load the associated provider, you cannot pass both the Provider and File Name arguments.

因为File Name参数可以引起ADO加载自定义的提供者,你不能同时加载Provider和File Name参数属性。

The ConnectionString property is read/write when the connection is closed and read-only when it is open.

Connection关闭时,ConnectionString是可读写的;连接打开时,ConnectionString又是只读的。

Remote Data Service Usage When used on a client-side Connection object, the ConnectionString property can only include the Remote Provider and Remote Server parameters.

远程数据服务的使用方法:当使用客户端连接对象时,ConnectionString属性只包含Remote Provider和Remote Server 参数属性。

Examples

ConnectionString, ConnectionTimeout, and State Properties Example (VB)

See Also

Using OLE DB Providers with ADO

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值