Compact Access Database with C #

1

I have a method to compress my base Access , however when I run the program I get the following error:

Error:

  

The exception to catch is this message: {"Retrieving the COM class factory for component with CLSID {DE88C160-FF2C-11D1-BB6F-00C04FAE22DA") failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). "} System.Exception {System.Runtime.InteropServices.COMException}

I could not identify. Here is the code:

try
{
    JRO.JetEngine jetEngine = (JRO.JetEngine)Activator                        
                     .CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));
    var arquivoTemporario = System.IO.Path.GetTempFileName();
    arquivoTemporario = System.IO.Path.ChangeExtension(arquivoTemporario, "mdb");
    string templateConnectionString = "Data Source={0};Provider=Microsoft.Jet.OLEDB.12.0;";
    string connectionStringFonte = string.Format(templateConnectionString, caminhoMdb);
    string connectionStringTemp=string.Format(templateConnectionString,arquivoTemporario);

    jetEngine.CompactDatabase(connectionStringFonte,connectionStringTemp);
    System.IO.File.Copy(arquivoTemporario, caminhoMdb, true);
    System.IO.File.Delete(arquivoTemporario);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
    
asked by anonymous 27.11.2017 / 13:51

1 answer

1

In Visual Studio go to project properties, on the Build tab select the platform target = X86 option.

Source: Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154

    
27.11.2017 / 17:00