10-31-2011، 03:28 PM
کد:
public static void CompactAccessDB(string connectionString, string mdbfilename)
{
object[] oParams;
object objJRO =
Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));
oParams = new object[] {
connectionString,
"Provider=Microsoft.Jet.OLEDB.4.0;Data" +
" Source=C:\\tempdb.mdb;Jet OLEDB:Engine Type=5"};
objJRO.GetType().InvokeMember("CompactDatabase",
System.Reflection.BindingFlags.InvokeMethod,
null,
objJRO,
oParams);
System.IO.File.Delete(mdbfilename);
System.IO.File.Move("C:\\tempdb.mdb", mdbfilename);
System.Runtime.InteropServices.Marshal.ReleaseComObject(objJRO);
objJRO = null;
}