Class not recognized C # WINDOWS FORMS

1

I'm having a new problem in the same method, instead of bold italic accuses an unrecognized class problem, any hint how to solve? Code below:

public static void CompactarMdb(string caminhoaccdb){
        JRO.JetEngine jetEngine = (JRO.JetEngine)Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));
        var arquivoTemporario = System.IO.Path.GetTempFileName();
        arquivoTemporario = System.IO.Path.ChangeExtension(arquivoTemporario, "accdb");
        string templateConnectionString = "Data Source={0}; Provider=Microsoft.Jet.OLEDB.12.0;";
        string connectionStringFonte = string.Format(templateConnectionString, caminhoaccdb);
        string connectionStringTemp = string.Format(templateConnectionString, arquivoTemporario);
        ***jetEngine.CompactDatabase(connectionStringFonte, connectionStringTemp);***
        System.IO.File.Copy(arquivoTemporario, caminhoaccdb, true);
        System.IO.File.Delete(arquivoTemporario);
}
    
asked by anonymous 27.11.2017 / 19:22

1 answer

1

You need to add the reference to the file

  

msjro.dll

Find it on your PC, in my case it was on:

  

C: \ Windows \ WinSxS \ wow64_microsoft-windows-m..replication-objects_31bf3856ad364e35_10.0.16299.15_none_ad8010ef4b16f751

link

Update

After discussion in the chat worked with the following code:

Need to add reference to

  

Microsoft Office 14.0 Access Database Engine Object Library

string sourceDbSpec = @"C:\temp\testdb.accdb"; 
string destinationDbSpec = @"C:\temp\compactado.accdb"; 

// Required COM reference for project: 
// Microsoft Office 14.0 Access Database Engine Object Library 
var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine(); 
try 
{ 
    dbe.CompactDatabase(sourceDbSpec, destinationDbSpec); 
} 
catch (Exception e) 
{ 
    Console.WriteLine("Error: " + e.Message); 
}
    
27.11.2017 / 21:36