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
Karenjit KaurPosted Dec 6, 2017, 12:20 AM
David SmithPosted Oct 29, 2010, 11:45 PM
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;