我写了一个应该在很多机器上运行的程序
我没有在机器上安装 Access 但是我有一个在它们上使用的 access 数据库
当我从这个 Access 数据库写入和删除数据时,它的大小会增加,所以每隔几天我就必须压缩它们并缩小大小
这是我使用的代码
public void Compacting()
{
try
{
Microsoft.Office.Interop.Access.Application application = new Microsoft.Office.Interop.Access.Application();
string dbName = "";
try
{
dbName = ConfigurationManager.ConnectionStrings["LocalPulserDB"].ConnectionString.Split("Data Source=").Last().Split(";").First();
}
catch (Exception ex)
{
string localDbError = "DataBase location is incorrect ";
System.Windows.MessageBox.Show(localDbError);
Environment.Exit(1);
}
CompactAndRepair(dbName, application);
}
catch (Exception ex)
{
try
{
LocalPulserDBManagerInstance.WriteLog(ex.StackTrace, ex.Message);
}
catch (Exception)
{
}
}
}
private void CompactAndRepair(string accessFile, Microsoft.Office.Interop.Access.Application app)
{
string tempFile = Path.Combine(Path.GetDirectoryName(accessFile),
Path.GetRandomFileName() + Path.GetExtension(accessFile));
app.CompactRepair(accessFile, tempFile, true);
app.Visible = false;
FileInfo temp = new FileInfo(tempFile);
temp.CopyTo(accessFile, true);
temp.Delete();
}
但我得到了下一个错误:
{"Retrieving the COM class factory for component with CLSID {73A4C9C1-D68D-11D0-98BF-00A0C90DC8D9} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))."}
我能做些什么?