Unrecognized class C# WINDOWS FORMS

Asked

Viewed 149 times

1

I have a new problem in the same method, the place in bold and italics accuses an unrecognized class problem, some hint how to solve? Code to follow:

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

1 answer

0


You need to add the reference to the file

msjro.dll

Locate 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

https://support.microsoft.com/en-us/help/230501/how-to-compact-microsoft-access-database-through-ado

Update

After discussion in chat worked with the following code:

Required 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); 
}
  • I made the reference, but the error persists, I do not rule out to have made wrong, some hint to reference ?

  • In Solution Explorer right click on References and Add Reference. It will open a window, click Browser and locate the DLL, after that can give OK. Note later that this new reference will be inside the references tab there. Here I did the same the code compiled normally.

  • I did, but the problem persists, unfortunately

  • But even compile (build) or not even that? or error when it will run?

  • Compiled and rotated, but when I run the code I posted here, the unrecognized class error persists

  • I’ll test it here, I’ll hunt a mdb to do.

  • 1

    Solved the problem, thank you so much for the help on chat. Hug!

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.