is it possible to compact the Msaccess database using c# if so let me know the way?
You can try something like this
public static void CompactAndRepair(string accessFile, Microsoft.Office.Interop.Access.Application app)
{
string tempFile = Path.Combine(Path.GetDirectoryName(accessFile),
Path.GetRandomFileName() + Path.GetExtension(accessFile));
app.CompactRepair(accessFile, tempFile, false);
app.Visible = false;
FileInfo temp = new FileInfo(tempFile);
temp.CopyTo(accessFile, true);
temp.Delete();
}
See also Use the CompactRepair method of the Application object to compact and repair the database
...
//invoke a CompactDatabase method of a JRO object
//pass Parameters array
objJRO.GetType().InvokeMember("CompactDatabase",
System.Reflection.BindingFlags.InvokeMethod,
null,
objJRO,
oParams);
...
See more details at http://www.codeproject.com/KB/database/mdbcompact_latebind.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With