using JRO //引用
public void Compact(string mdbPath)
{if (!File.Exists(mdbPath))
{
throw new Exception("目标数据库不存在,无法压缩!");
}
//临时数据库名称
string temp = DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak";
//临时数据库地址(包含名称)
temp = mdbPath.Substring(0, mdbPath.LastIndexOf("\\")+1) + temp;
//临时数据库连接字符串
string temp2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+temp;
//原始数据库连接字符串
//压缩Access数据库工具类(.dll c:\C:\Program Files (x86)\Common Files\System\ado\msjro.dll)
JetEngineClass jt = new JetEngineClass();
jt.CompactDatabase(mdbPath2,temp2);
File.Copy(temp,mdbPath,true);
File.Delete(temp);
}