views:

242

answers:

3

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  A: 

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

Rubens Farias
This is the correct answer, as far as I can see, and there is even a heading "With database password" in the link to make life easy.
Remou
Maybe link to http://connectionstrings.com/access instead? The file in question is a mdb database, not accdb.
Heinzi
@Heinzi, just updated that link, ty
Rubens Farias
+3  A: 

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;
Pbirkoff
As the poster states, "Entering username and password in connection string is not working"
Rob Cowell
+1, since, as it turns out, this might happen to be the correct answer. (The author specified the password in the wrong way.)
Heinzi
In the original unedited post, he didn't show how he was specifying it at all. Nice to see more detail in the edits now :-)
Rob Cowell
+2  A: 

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
Heinzi
This is for a secured database, not a password protected database.
Remou
@Remou: Then why does Shntanu talk about passing the "user name" in the connection string?
Heinzi
Shantanu distinctly says database password, so I suspect that user name and password is a misunderstanding in this case.
Remou
@Remou : I also want a secure database so that no one can open the file other than a developer itself. So i only want that file to be password protected. If user deletes that file that is not a problem but he cannot open that file in any case. As this application has to be run on pendrive.
Shantanu Gupta
Did you use a Database Password of Access Security?
Remou
@Remou: Thanks for the feedback. I've adapted my answer to emphasize that it only applies to the "secured database" case.
Heinzi