I want to write into Access Database File using C# Application, probably using WPF ... I also want the file to be password protected ... is it possible to connect to it while it is password protected or should I remove the password?
-
1Do you mean a Jet user-level security password, or a database password? If the former, you're OK with ODBC or OLEDB. If the latter, only ODBC supports a database password -- you're out of luck with OLEDB. Database passwords are a complete waste of time an effort in any case, so if it's a database password, you should consider just getting rid of it entirely.David-W-Fenton– David-W-Fenton2010-07-12 18:49:21 +00:00Commented Jul 12, 2010 at 18:49
Add a comment
|
3 Answers
Use OleDbConnection (System.Data.OleDb) and the right connection string.
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;
2 Comments
sikas
OleDb conn = new OleDb("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;"); ... can I set the data source to something like Data Source=mysource; ?? but for the username, what will it be? as the access takes password only to lock the file ...
Raj More
the default username is
AdminOur C# .Net4.0 Windows Forms data connection to MS Access looks like this:
using System.Data.OleDb;
...
private void DoIt()
{
OleDbConnection NamesDB = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=CyberSprocket.mdb");
try
{
NamesDB.Open();
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
return;
}
OleDbCommand NamesCommand = new OleDbCommand("SELECT * FROM [names];", NamesDB);
OleDbDataReader dr = NamesCommand.ExecuteReader();
string theColumns = "";
for (int column = 0; column < dr.FieldCount; column++)
{
theColumns += dr.GetName(column) + " | ";
}
MessageBox.Show(theColumns);
NamesDB.Close();
}
Comments
Yes you can work with a password protected MS Access Database.
In your connection string to MS Access database, you can provide a USERNAME and PASSWORD.
Depending on which Security type is implemented, here are two samples:
Workgroup Security using a System Database
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Server\Share\MyData.mdb;Jet OLEDB:System Database=\\Server\Share\MyData.mdw;USER=userid, PWD=password"
With Standard MS Access Security:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Server\Share\MyData.mdb;User ID=userid;Password=password;"
4 Comments
sikas
I would like to see a code for the connection, write process and read process if possible
David-W-Fenton
The difference between your two examples is that the first specifies a workgroup file while the second will use whatever is defined as the default workgroup file for that version of Jet on that particular computer.
Raj More
@David-W-Fenton That's right. In addition to using whatever the default workgroup file suggests, it will also use the login info for that particular MDB, right?
David-W-Fenton
If you don't specify one of the arguments, it will use the defaults. For workgroup, that's whatever is set as the default workgroup file. For username, it's admin, and for password, none.