2008年1月14日星期一

Corrupt apollo.mdb bings unpack.exe "Failed to create empty document. "

CDaoDatabase::Open()本身是void,当遇到.mdb结构性破坏时,无法返回错误报告。
解决方案:利用抛出异常返回结果
BOOL CPublic::openDB()
{
......
//----build connection to source Datenbase by CDaoDatabase.
// *here must check the sourceDB is the right .mdb file and kann be found
// it can be the wrong .mdb file , "test.mdb"
try
{
CDaoWorkspace daoWorkspace;
//CDaoWorkspace::CompactDatabase( _T( "C:\\DB1.MDB" ),_T( "C:\\DB2.MDB" ) );
//CDaoWorkspace::RepairDatabase( (LPCTSTR)sourceDB );
daoWorkspace.Open( (LPCTSTR)sourceDB );
if (!daoWorkspace.IsOpen())
return false;
else
daoWorkspace.Close();

}
catch( CDaoException* e )
{
//AfxMessageBox( e->m_pErrorInfo->m_strDescription );
e->Delete();
return false; //利用CDaoWorkspace::Open可避免.lpb文件的产生,造成死锁

}
//----build connection to source Datenbase by CDaoDatabase.
// *here must check the sourceDB is the right .mdb file and kann be found
// it can be the wrong .mdb file , "test.mdb"

try
{
m_DaoDatabase.Open((LPCTSTR)sourceDB,FALSE,FALSE,_T(""));

}
catch(CDaoException* e)
{
e->Delete();
return false; //important, if .mdb corrupt ist.

}
//
......
return true;

}

没有评论: