简体   繁体   中英

Connect password protected access file

I want to connect with password protected access file. with below coding, I am getting an error as "Incorrect password" but when I open it manually with the same password, its open. Do I get to make any changes in database setting.

Dim Acon As New ADODB.Connection
Dim Rs As New ADODB.Recordset

With Acon
    .Provider = "Microsoft.ACE.OLEDB.12.0"
   .ConnectionString = "Data Source=" + "U:\scratch\OK.accdb"
    .Properties("Jet OLEDB:Database Password") = "123"
    .Open
 End With

Yes you will get that problem. To sort it, follow the steps exactly as I tell you

  1. Close your database
  2. From Access, click on File|Open and then open your database as Exclusive 在此处输入图片说明
  3. Decrypt the database from the File menu

    在此处输入图片说明

  4. Click on File|Options|Client Settings and navigate to the end and select the options shown below 在此处输入图片说明

  5. Encrypt your database after you click OK in the above screen.
  6. Close the database and then try the code

Code I used for testing

Sub Sample()
    Dim Acon As New ADODB.Connection
    Dim Rs As New ADODB.Recordset

    With Acon
        .Provider = "Microsoft.ACE.OLEDB.12.0"
        .ConnectionString = "C:\Users\Siddharth\Desktop\Database3.accdb"
        .Properties("Jet OLEDB:Database Password") = "test"
        .Open
     End With
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM