我们在用ado连接数据时,经常会出现一些异常,而用_com_error::ErrorMessage()有时候给出的错误信息又太不直观。因此,我给出下面的代码,以期得到更加全面直观的错误信息
long lErrCount= pConn->GetErrors()->GetCount(); //pConn是你的连接变量,_ConnectionPtr型
_bstr_t add;
CString strErrMsg,strTmp;
for (short i=0;i<lErrCount;i++)
{
add = pConn->GetErrors()->GetItem(_variant_t((short)i))->GetDescription();
strTmp= (char *)add;
strErrMsg += strTmp;
}
AfxMessageBox(strErrMsg);
long lErrCount= pConn->GetErrors()->GetCount(); //pConn是你的连接变量,_ConnectionPtr型
_bstr_t add;
CString strErrMsg,strTmp;
for (short i=0;i<lErrCount;i++)
{
add = pConn->GetErrors()->GetItem(_variant_t((short)i))->GetDescription();
strTmp= (char *)add;
strErrMsg += strTmp;
}
AfxMessageBox(strErrMsg);