2
votes

I am creating a window application in C# and was thinking of setting up a password on mdb file of MS-Access so that no one can open that file other than my window application or who so ever knows password of that file.

I managed to make that file password protected but unfortunately I was not able to access that file through my application. Actually i not getting where to set the user name and password to open that file. Entering username and password in connection string is not working.

EDIT Sorry for bit confusion

I want that file to be password protected rather than database connection. That file should not be opened in any case. For that i managed to set password on file using ms access itself but i m not able to open that file through my application.

Edit2: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Projects\GargTubes\dbGargTubes.mdb; User Id=""; Password="abc";"

I am using MS-Access 03

Edit 3:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Projects\GargTubes\dbGargTubes.mdb; Database Password=abc;"

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Projects\GargTubes\dbGargTubes.mdb;JET OLEDB: Database Password=abc;

Error: Could not find installable ISAM

3
Database passwords are very flimsy.Fionnuala
Can you clarify how you locked down the database? There seem to be at least two options for that.Heinzi
Did you use Access Security or a Database Password?Fionnuala
@Shantanu: Can you show us the connection string that you are currently using (and which is not working)? Second question: When opening the DB in Access, do you have to enter user name and password or only a password?Heinzi
@Shantanu: Exactly means exactly. ;-) Don't add a space between Jet OLEDB: and Database Password.Heinzi

3 Answers

2
votes

Since you are talking about passing user name and password, I assume that you have protected your database by setting user rights rather than by using the "database password" option. In that case, users and groups are stored in system.mdw. Be sure to include the path to system.mdw in your connection string (Jet OLEDB:System Database=path\to\system.mdw, see Connection strings for Access for samples).

Alternatively, you use the "database password" feature. Then, the Jet OLEDB:Database Password option described in the other answers should work. To spell it out:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Projects\GargTubes\dbGargTubes.mdb;Jet OLEDB:Database Password=abc
3
votes

Try setting the database password in your connection string:

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

You can take a look into that connection strings samples: Connection strings for Access