1

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?

1
  • 1
    Do 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. Commented Jul 12, 2010 at 18:49

3 Answers 3

2

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=;

Sign up to request clarification or add additional context in comments.

2 Comments

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 ...
the default username is Admin
2

Our 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

1

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

I would like to see a code for the connection, write process and read process if possible
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.
@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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.