方法如下
/// <summary> /// 压缩数据库 /// </summary> /// <param name="dbFileName"></param> public 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 ex) { MessageBox.Show("数据库压缩中出现错误!\r\n\r\n" + ex.Message); }
标签:objJRO,string,dbFileName,C#,数据库,object,System,Access From: https://www.cnblogs.com/Kirito-Asuna-Yoyi/p/CompactAccessDB.html