/// <summary>
/// 壓縮數據庫
/// </summary>
/// <param name="connectionString">數據庫鏈接</param>
/// <param name="mdwfilename">要壓縮的MDB文件的全名</param>
static void CompactAccessDB(string dbFileName)
{
try
{
string connectionString1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbFileName;
string connectionString2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C://temp.mdb";
object objJRO = Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));
object[] oParams = new object[] { connectionString1, connectionString2 };
objJRO.GetType().InvokeMember("CompactDatabase", System.Reflection.BindingFlags.InvokeMethod, null, objJRO, oParams);
System.IO.File.Delete(dbFileName);
System.IO.File.Move("C://temp.mdb", dbFileName);
System.Runtime.InteropServices.Marshal.ReleaseComObject(objJRO);
objJRO = null;
}
catch (Exception)
{
//MessageBox.Show("數據庫壓縮中出現錯誤!");
}
}