Conexión .accdb cifrada en C#

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 a Microsoft.ACE.OLEDB.12.0

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

Encriptar con contraseña

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\\;
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).

preguntado el 22 de mayo de 12 a las 15:05

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! :] -

Password is shorter than 10 chars :) ... Thanks for the tip though -

Stange one. Good luck, if I think of any thing, like Arnie "I'll be back"... -

1 Respuestas

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 = ""
    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
    Set cn = Nothing
End Sub

Editar: Apparently Access 2010 provides a stronger encryption method than earlier Access versions. With 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.

contestado el 23 de mayo de 12 a las 15:05

Thanks for the sample. I have tried to init a connection with this connection string from PowerShell but I have the same results. Surely I am doing something wrong - thedev

Start Access and see whether you can still open Perhaps it is corrupted as the error message suggests. Make sure you try that from the same user account which runs the failing c# code. - HansUp

I'm guessing this is due to the encryption method. Access 2010 can open it, but Access 2007 can't. However I haven't used Access 2010, so I'm only speculating ... but see whether the edit to my answer points you to something useful. - HansUp

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.