C# compact and repair access database
Do some one know how to compact and compare access database through code, i know how to do it outside of code, I want to automate the compact and compare option through code after i import data or delete data in the database
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

David SmithRank #999 · 2K reputationPosted Oct 29, 2010, 7:45 PM EDT
object objJRO =
Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));
oParams = new object[] {
Properties.Settings.Default.ConnectionString,
"Provider=Microsoft.Jet.OLEDB.4.0;Data" +
" Source=C:\\ElauDatabase.mdb;Jet OLEDB:Engine Type=5"};
objJRO.GetType().InvokeMember("CompactDatabase", ////////// I get a error right here at this line, Exception has been thrown by the target of an invocation.
System.Reflection.BindingFlags.InvokeMethod,
null,
objJRO,
oParams);
System.IO.File.Delete(Properties.Settings.Default.ConnectionString);
System.IO.File.Move("C:\\Database.mdb", Properties.Settings.Default.ConnectionString);
System.Runtime.InteropServices.Marshal.ReleaseComObject(objJRO);
objJRO = null;
Karenjit Kaur3 reputationPosted Dec 5, 2017, 7:20 PM EST