Open MS Acess with password protected in c#

X

-xx-

Hi,

I am new to c# and just trying out c# with ms access. First problem i
encountered is how do i open up ms access that has password.

Here is my current codes which working fine if there is no password on ms
access:

//Specify sql server-specific connection string
private const string strdns = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=f:\sample1.mdb";

//Main connector
public OleDbConnection thisconnection;

public clsDBBasic()
{
//Open the database
try
{
thisconnection = new OleDbConnection(strdns);
thisconnection.Open();
}
catch
{
throw new Exception("Open data error.");
}
}



Can anyone please tell me how to open ms access with password protected? I
have tried change the STRDNS variabale to

private const string strdns = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=f:\sample1.mdb;ID=sa;PWD=abc123;Persist Security Info=true"; //Not
working

private const string strdns = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=f:\sample1.mdb;OLEDB Password=abc123"; //Not working
 
M

Mark Rae

Can anyone please tell me how to open ms access with password protected? I
have tried change the STRDNS variabale to

private const string strdns = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=f:\sample1.mdb;ID=sa;PWD=abc123;Persist Security Info=true"; //Not
working

private const string strdns = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=f:\sample1.mdb;OLEDB Password=abc123"; //Not working

private const string strdns = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=f:\sample1.mdb;Jet OLEDB:Database Password=abc123;"
 
R

RobinS

Here's my connection string for connecting to an Access
database that has a database password. Sorry, this is VB,
but I think you can just change the & to + to do C#.

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\MyDatabase.mdb;" & _
"Persist Security Info=False;Jet OLEDB:Database Password=mypassword"

Robin S.
 
B

beaker

Mark said:
private const string strdns = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=f:\sample1.mdb;Jet OLEDB:Database Password=abc123;"

I was about to ask the very same question!

Is the only way to tell if the DB is password protected to catch the
exception thrown by Open() and check the message for 'Not a valid
password'? Just seems a bit untidy to me.

Thanks,

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top