Ben
Ben

Reputation: 2725

Accessing a password protected MS access database in C# issue

I am trying to connect a password protected database in C# using DAO. The code I have previously worked correctly with an unprotected database. Now when trying to connect to the database with adding a default password it is not working.

    var dbe = new DBEngine();
    dbe.DefaultPassword = "abc123";
    Database db = dbe.OpenDatabase(@"C:\Users\x339\Documents\Test.accdb");

I get the error: 'Cannot start your application. The workgroup information file is missing or opened exclusively by another user.' I'm not really sure where I'm going wrong here. Any help would be appreciated.

Upvotes: 2

Views: 1133

Answers (1)

DavidG
DavidG

Reputation: 119116

Well I wouldn't advise using DAO anymore, but if you must, use this code:

var dbe = new DBEngine();
var databaseFile = @"C:\Users\x339\Documents\Test.accdb";
var password = "abc123";
Database db = dbe.OpenDatabase(databaseFile, False, False, string.Format("MS Access;PWD={0}", password));

Upvotes: 4

Related Questions