今天进行一个学生信息系统的查询开发时,发现老师给的数据库(Access)有密码,不知道怎么连接了,在通常的数据连接中,我添加了password属性后,提示说我的密码错误,无法连接,刷新了一下后提示说:“文件正在使用或其他的程序以独占的方式打开了”,怎么办,以前没有遇到过此类问题啊!傻了,那就看看MSDN 的帮助,以下是查询的connectionString的说明,简单的翻译以下(红色的部分翻译得不好,希望大家帮忙看看)。
ConnectionString Property - ADO
Contains the information used to establish a connection to a data source.
提供给connection的数据库连接的信息,返回值为一个字符串
Applies To
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