views:

82

answers:

3

hi

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.

+4  A: 
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 @.

Nissan Fan
+1 for the connectionstrings.com ;)
Arcturus
+1  A: 

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

RedFilter
Er, what backslash needs to be escaped? And in what context?
David-W-Fenton
The only backslash in the original post; in the context of a C# string.
RedFilter
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.
David-W-Fenton
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.
RedFilter
I think you're assuming too much about your readers and about the context in which your answer may be read.
David-W-Fenton
+1  A: 

Try this:

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

Nick