using JRO //引用 public void Compact(string mdbPath) { if (!File.Exists(mdbPath)) { throw new Exception(目标数据库不存在,无法压缩!); } //临时数据库名称 string temp = DateTime.Now.ToString(yyyyMMddHHmmss) .bak; //临时数据库地址(包含名称
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;
//原始数据库连接字符串
string mdbPath2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath;
//压缩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);
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn