Gold
Gold

Reputation: 62554

how to open access database with password in C#?

how can I open an MS Access 2007 database with a password in c# ?

I have tried this: Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\BioDB.mdb ;Password=1966;");

but it doesn't work.

Upvotes: 2

Views: 27697

Answers (4)

Erwin Draconis
Erwin Draconis

Reputation: 784

This is the connection string to use when you have an Access 2007 - 2013 database protected with a password using the "Set Database Password" function in Access.

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;
Jet OLEDB:Database Password=MyDbPassword;

Some reports of problems with password longer than 14 characters. Also that some characters might cause trouble. If you are having problems, try change password to a short one with normal characters.

Upvotes: 0

Nick
Nick

Reputation: 5955

Try this:

@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=BioDB.mdb;Jet OLEDB:Database Password=1966;"

Upvotes: 2

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171549

You'll need to escape that backslash, or precede the string with @.

Upvotes: 1

Keith Adler
Keith Adler

Reputation: 21178

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;Jet OLEDB:Database Password=MyDbPassword;

From:

http://www.connectionstrings.com/access

And as noted below use @.

Upvotes: 13

Related Questions