views:

51

answers:

0

I have two MS Access accdb databases. Both database are password protected. The first database I can compact fine no issues at all. Below is the code that I use to compact it.

    object[] oParams;
    object objJRO = Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));

    oParams = new object[] {
    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\database.accdb;Jet OLEDB:Database Password=mypassword;Jet OLEDB:Engine Type=5",
    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\tempdb.accdb;  Jet OLEDB:Database Password=mypassword;Jet OLEDB:Engine Type=5"};

    objJRO.GetType().InvokeMember("CompactDatabase",
        System.Reflection.BindingFlags.InvokeMethod,
        null,
        objJRO,
        oParams);

The problem is the second database. It throws the following exception. Message="Not a valid password." Source="Microsoft Office Access Database Engine" ErrorCode=-2147467259

What is unique about the second database is that it links to the first database. If I remove all the linked tables from the second database I can compact it fine, as soon as I add one linked table back again the exception comes back.