tags:

views:

45

answers:

1

Using Visual Studio 2010 with a C# WPF project. I know how to create an Access 2000-2003 db file using the ADOX namespace.

ADOX.CatalogClass cat = new CatalogClass();
string str = "provider=Microsoft.Jet.OleDb.4.0;Data Source=" + _dbPath + ";";
cat.Create(str);
cat = null;

Connect and open the database:

conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" 
       + _dbPath + ";");

//connect to it with a password
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _dbPath + ";User Id=admin;Password=myPassword;"

I want to create the file password protected:

ADOX.CatalogClass cat = new CatalogClass();
string str = "provider=Microsoft.Jet.OleDb.4.0;Data Source=" 
+ _dbPath + ";Password=myPassword;";
cat.Create(str);
cat = null;

This produces an error at runtime:

Cannot start your application. The workgroup information file is missing or opened exclusively by another user.

When I create without the password, the database is created successfully.

How can I create a password protected Access database with this strategy?

A: 

If you mean a database password, rather than user level security, which requires a workgroup file, you can change the connection string to include:

 Jet OLEDB:Database Password=MyDbPassword;

That is:

ADOX.Catalog cat = new CatalogClass();
string str = "provider=Microsoft.Jet.OleDb.4.0;Data Source=" 
+ _dbPath + ";Jet OLEDB:Database Password=MyDbPassword;";
cat.Create(str);
cat = null;

-- http://www.connectionstrings.com/access

Using the information here: http://support.microsoft.com/kb/317881, with some minor changes:

ADOX._Catalog cat = new ADOX.Catalog();

cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=PW;" +
       "Data Source=C:\\Docs\\NewMDB.mdb;");

I find I can create a password protected Access database.

Remou
this is for the connection to the database, it didn`t work for the creation! I get this error that informs me that the database is opened exclusively by another user or that I need permission to view its data. Yet the database is not yet created!!
sikas
I have added some notes.
Remou
I have tried this before, Remou. But it failed!! I think I`ll just encrypt everything in the database or see how to work with the resources ...
sikas