0

I'm trying to protect a Access database by using a workgroup file as user-security. The file must be in the same folder as the database and you must enter a user name and password to access the database. I read something about the parameter "System Database" in connectionString, but I'm not sure how to use it. The database is created like this:

String accessConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + filepath";

using (OleDbConnection accessConnection = new OleDbConnection(accessConnectionString))
{
  ADOX.Catalog cat = new ADOX.Catalog();
  cat.ActiveConnection.Close();
  var newCreatedCatalog= cat.Create(accessConnectionString);
  OleDbCommand oleCommand = new OleDbCommand();
  // fill database
}
Scorch
  • 153
  • 2
  • 17
  • 2
    I very much doubt you can do this with ADOX. Workgroup files and Access user-level security have since long been deprecated, and have been proven to be insecure. Why do you want to do this in the first place? – Erik A Jun 15 '18 at 10:27
  • Thank you for your fast reply. I'm looking for a way to protect the created database. I am relatively inexperienced with Access, can you recommend alternatives since my approach seems to be false? – Scorch Jun 15 '18 at 10:35
  • 2
    Access offers very little security features. If you want true security, there's basically encrypting the whole database with a single password, and nothing else. Also, the most easy way to work with Access databases often is DAO, which is used by Access itself. The DAO DBEngine object allows you to create new databases (The DAO PrivateDbEngine was used for workgroup files, but is almost entirely undocumented, and as said, not a good choice). – Erik A Jun 15 '18 at 10:41
  • By using a single password, do you mean setting it in the connectionString or by using the property DefaultPassword from DAO? – Scorch Jun 15 '18 at 11:05
  • 1
    If you want to create a database with DAO, you shouldn't use a connection string at all. You just create the database engine object, and then call [`.CreateDatabase`](https://msdn.microsoft.com/en-us/library/office/ff835033.aspx), and specify `";pwd=SomePassword"` in the second argument. If you want to connect to that database afterwards, you need to use a connection string with a password, like [this](https://www.connectionstrings.com/microsoft-jet-ole-db-4-0/with-database-password/) – Erik A Jun 15 '18 at 11:10

0 Answers0