how to open access database with password in C#?

24,676

Solution 1

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 @.

Solution 2

Try this:

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

Solution 3

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

Share:
24,676
Gold
Author by

Gold

Updated on April 19, 2020

Comments

  • Gold
    Gold about 4 years

    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.

  • David-W-Fenton
    David-W-Fenton about 14 years
    Er, what backslash needs to be escaped? And in what context?
  • D'Arcy Rittich
    D'Arcy Rittich about 14 years
    The only backslash in the original post; in the context of a C# string.
  • David-W-Fenton
    David-W-Fenton about 14 years
    OK. C# programmers would understand that, but I think it would be better to be more explicit in an answer in specifying exactly what you're addressing.
  • D'Arcy Rittich
    D'Arcy Rittich about 14 years
    The OP stated they are using C# and the question is tagged C#. I think it is a bit redundant to keep stating the language.
  • David-W-Fenton
    David-W-Fenton about 14 years
    I think you're assuming too much about your readers and about the context in which your answer may be read.
  • Admin
    Admin almost 7 years
    how about username?
  • Admin
    Admin almost 7 years
    how about username?