4
votes

I recently updated my database from .mdb (MS Access 2003) to .accdb (MS Access 2010).

With this update I also updated my provider from: Microsoft.Jet.OLEDB.4.0 to Microsoft.ACE.OLEDB.12.0

The connection works ok when I use a .accdb file without a password, but once I choose to

Encrypt with Password

I receive the following error when I try to open a connection.

Cannot open database ''. It may not be a database that your application recognizes, or the file may be corrupt.

Used connection string:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\App\\Main\\bin\\Debug\\db.xxx;
Jet OLEDB:Database Password=MyPass;

Note: I use a custom extension for my .accdb file, this was used for .mdb files without problems and I assume this should not be a problem (tested).

1
There have been reports of problems with password longer than 14 characters. Also that some characters might cause trouble. Try changing password to a short one with normal characters. If you are using the password you have shown - the above is clearly no help to you! :] - MoonKnight
Password is shorter than 10 chars :) ... Thanks for the tip though - thedev
Stange one. Good luck, if I think of any thing, like Arnie "I'll be back"... - MoonKnight

1 Answers

1
votes

I don't see a problem with your connection string. Still I would try it from VBA to see whether that effort sheds any light on the problem.

This one worked from Access 2007 whether I named the db file with "accdb" or "xxx" file extension. The single quotes are not required around my password; the code succeeded whether or not I included the single quotes.

Public Sub OleDbToEncryptedAccdb()
    'Const cstrDb As String = "encryptd.accdb" '
    Const cstrDb As String = "encryptd.xxx"
    Const cstrFolder As String = "C:\share\Access"
    Const cstrPassWord As String = "letmein"
    Dim cn As Object
    Dim strConnect As String

    strConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
        cstrFolder & Chr(92) & cstrDb & _
        ";Jet OLEDB:Database Password='" & cstrPassWord & "';"
    Debug.Print strConnect
    Set cn = CreateObject("ADODB.Connection")
    cn.ConnectionString = strConnect
    cn.Open
    cn.Close
    Set cn = Nothing
End Sub

Edit: Apparently Access 2010 provides a stronger encryption method than earlier Access versions. With db.xxx open in Access 2010, check which ACE version is used as the Provider.

? CurrentProject.Connection.Provider

If it replies something like Microsoft.ACE.OLEDB.14.0, use that in your c# connection string.