Connecting to Microsoft Access

ADO connects to Microsoft Access databases through the use of the Microsoft Office 12 Access Database Engine OLE DB Provider. To connect to a Microsoft Access database, you simply specify this provider in the ADO connection string and then include any additional provider-specific arguments required. The following is a summary of the connection string arguments you will most frequently use when connecting to an Access database:

□ Provider=Microsoft.ACE.OLEDB.12.0(required)

□ Data Source=[full path and filename to the Access database] (required)

□ Mode=mode (optional) —The three most commonly used settings for this property are:

□ adModeShareDenyNone — Opens the database and allows complete shared access to other users. This is the default setting if the Mode argument is not specified.

□ adModeShareDenyWrite — Opens the database and allows other users read access but prevents write access.

□ adModeShareExclusive — Opens the database in exclusive mode, which prevents any other users from connecting to the database.

□ User lD=username (optional) —The username to use when connecting to the database. If the database requires a username and it is not supplied, the connection will fail.

□ Password=password (optional) — If a password is required to connect to the database, this argument is used to supply it. Again, the connection will fail if it is required and not supplied, or is incorrect.

The following example shows a connection string that uses all of these arguments:

Public Const gsCONNECTION As String = _

"Provider= Microsoft.ACE.OLEDB.12.0;'

' & _

"Data Source=C:\Files\Northwind 2007.

.accdb;" & _

"Mode=Share Exclusive;" & _

"User ID=Admin;" & _

"Password=password"

0 0

Post a comment