Connection to protected access accdb file throws “

2019-08-11 09:37发布

问题:

I am trying to connect to an encrypted access 2013 accdb file which is using legacy encryption through an adodb vba procedure within an excel file.

The Procedure fails at cn.open, I am using office 64 bits, error message: "It is not a valid Password". The particularity of this problem is, the password is correct, I can connect to the Access DB through Microsoft query just fine, and I can connect with another access DB with the code below. But when I try to use it on Excel, this error jumps in, take note, I have enabled the same references on both access and excel vba editor.

My question is, how can I extract data from this password protected access file through excel, each and every method I try fail after I have typed the password.

VBA Procedure

Sub LDBViewer2010()
'Reference Microsoft ActiveX Data Objects for this code to work

Dim cn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Const conDatabase As String = "E:\1.accdb"

    ' Open connection to Access backend
   cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & conDatabase & ";Persist Security Info=False;Jet OLEDB:Database Password='asd123';"

    ' Open recordset
   Set Rs = cn.OpenSchema(adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")

    'Output the field list
   Debug.Print Rs.Fields(0).Name, "|", Rs.Fields(1).Name, "|", Rs.Fields(2).Name, "|", Rs.Fields(3).Name

    'Loop through users recordset of users in database.
   While Not Rs.EOF
        Debug.Print Trim(Rs.Fields(0)), "|", Trim(Rs.Fields(1)), "|", Trim(Rs.Fields(2)), "|", Trim(Rs.Fields(3))
        Rs.MoveNext
    Wend

    ' Close
   If Rs.State <> adStateClosed Then Rs.Close
    Set Rs = Nothing
    Set cn = Nothing

End Sub

I greatly appreciate your time and help.

-Edit 1-

Using debug.print CurrentProject.Connection.ConnectionString in Access:

Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=E:1.accdb;Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database=C:\Users\User\AppData\Roaming\Microsoft\Access\System.mdw;Jet OLEDB:Registry Path=Software\Microsoft\Office\15.0\Access\Access Connectivity Engine;Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=True;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False

回答1:

Solved it creating a new access file and doing some further testing. Below is what I found out.

Although I created my database with hereditary encryption, the password always failed whichever the method. I tried Decrypting and Re-encrypting with same password and now excel connects just fine.

Take note that only excel had trouble connecting, I could connect from another access DB without a hitch.

Thank you for your ideas & contributions, they helped me get the right answer.