TCHAR szDestSQL[100];
TCHAR szSQL[100];
try
{
::CoInitialize(NULL);
sprintf(szSQL,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Config.mdb;Jet OLEDB:DataBase Password=100100;");
IJetEnginePtr jet(__uuidof(JetEngine));
sprintf(szDestSQL,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ConfigTemp.mdb;");
strcat(szDestSQL,"Jet OLEDB:Engine Type=5");
jet->CompactDatabase(szSQL,szDestSQL);
DeleteFile("Config.mdb");
rename("ConfigTemp.mdb","Config.mdb");
::CoUninitialize();
}
catch(_com_error &e)
{
::MessageBox(NULL, (LPCTSTR)e.Description( ), "", MB_OK) ;
}
这段代码以前就有,但一直没成功过,今天加了try,,,catch才发现,原来是密码错误,以前没有把Jet OLEDB:DataBase Password=100100
写上,弄得苦恼了我很久