2

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.

Ben
  • 2,518
  • 4
  • 18
  • 31

1 Answers1

4

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));
DavidG
  • 113,891
  • 12
  • 217
  • 223
  • +1 for advice on methodology. Use OleDb...see: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection(v=vs.90).aspx – DonBoitnott May 29 '14 at 15:06
  • 1
    Works perfect, thanks. Before I accept as answer why would you suggest against DAO? can you link to some alternates? and documentation if possible. – Ben May 29 '14 at 15:06
  • Well I would start by asking if you really need to be using Access when SQL Express is free. – DavidG May 29 '14 at 15:21
  • My ACCDB database can't be changed. How can I offer support to compact without using DAO? I see the linked article but offers no explanation. My driver is JET Access .... – Andrew Truckle May 25 '22 at 11:09
  • 1
    @AndrewTruckle This is a question about DAO. If you have a question about something else, then you should post a new question. – DavidG May 25 '22 at 11:24
  • See: https://stackoverflow.com/q/72376928/2287576 – Andrew Truckle May 25 '22 at 11:38