简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM