/// <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("数据库压缩中出现错误!");
}
}