Opening a Microsoft Jet Database Secured with a Password

If a database is secured with a password, you have to specify the Jet OLEDB:Database Password property as part of a ConnectionString property, like this:

"Jet OLEDB:Database Password=secret;"

Passwords are case sensitive. Hands-On 10-4 demonstrates how to open a Microsoft Access database after it has been secured with a password.

©Hands-On 10-4: Opening a Password-Protected Database

1. Make a backup copy of the Northwind.mdb database and name it NorthSecure.mdb.

Creating and Manipulating Databases with ADO

2. Open the NorthSecure.mdb database file with exclusive access. (Choose File | Open, switch to the folder containing the NorthSecure.mdb file, highlight the name of the file, click the arrow next to the Open button, and choose Open Exclusive.)

3. Set the database password to "Secret" by choosing Tools | Security | Set Database Password and typing Secret.

4. Close the NorthSecure database.

5. Switch back to the Acc2003_Chap10 database (see Hands-On 10-2) and press Alt+F11 to activate the Visual Basic Editor window.

6. In the Visual Basic Editor window, choose Insert | Module.

7. In the module's Code window, type the Open_WithDbPassword procedure shown below.

8. Choose Run | Run Sub/UserForm to execute the procedure.

Sub Open_WithDbPassword()

Dim conn As ADODB.Connection Dim strDb As String On Error GoTo ErrorHandler strDb = CurrentProject.Path & "\NorthSecure.mdb" Set conn = New ADODB.Connection With conn

.Provider = "Microsoft.Jet.OLEDB.4.0;"

.ConnectionString = "Data Source=" & strDb & ";" & _ "Jet OLEDB:Database Password=secret;"

.Open End With

MsgBox "Password protected database was opened." conn.Close Set conn = Nothing MsgBox "Database was closed." Exit Sub ErrorHandler:

MsgBox Err.Number & ": " & Err.Description End Sub

0 0

Post a comment