void CAdoRecordset::dump_com_error (_com_error &e)
{
CString ErrorStr;
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
ErrorStr.Format("CADORecordset Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n",
e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
m_strLastError = _T("Query = " + GetQuery() + '\n' + ErrorStr);
// TRACE("%s\n", m_strLastError);
#ifdef _DEBUG
AfxMessageBox( m_strLastError, MB_OK | MB_ICONERROR );
#endif
}try
{
}
catch (_com_error &e)
{
dump_com_error ;
}
可以查看错误出现的原因!
你看一下是否有ADO类库,或是没有初始化COM类库
{
CString ErrorStr;
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
ErrorStr.Format("CADORecordset Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n",
e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
m_strLastError = _T("Query = " + GetQuery() + '\n' + ErrorStr);
// TRACE("%s\n", m_strLastError);
#ifdef _DEBUG
AfxMessageBox( m_strLastError, MB_OK | MB_ICONERROR );
#endif
}try
{
}
catch (_com_error &e)
{
dump_com_error ;
}
可以查看错误出现的原因!
你看一下是否有ADO类库,或是没有初始化COM类库
try{}
catch{}
来防止错误导致程序死掉
比如:
try
{
m_pConnection->Open(....);
}
catch(_com_error& e){ }
可能你的错误是数据源的问题
的是Oracle数据库,那么在每个客户机上都要先运行Oracle安装程序安装ADO插件后才能运行客户端程序。
com要初始化;
try
{
……
}
catch(_com_error &e)
{
MessageBox(e.Description());
}
pConnection.CreateInstance(__uuidof(Connection)); //实例化一个Connection指针
pCommand.CreateInstance( __uuidof( Command ) );//实例化一个Command指针