在執行SQL語句或者SQL文件失敗後,添加如下代碼可以獲得類似在查詢分析器中執行的錯誤信息: 參照以下地址:http://www.codeproject.com/KB/database/DBDevVCOLEDB.aspx
IErrorInfo* pErrInfo; HRESULT hr = ::GetErrorInfo(0, &pErrInfo); if(SUCCEEDED(hr)) { BSTR bstrErrDescription; pErrInfo->GetDescription(&bstrErrDescription); CString strDescription = bstrErrDescription; AfxMessageBox(LPCTSTR(strDescription); pErrInfo->Release(); ::SysFreeString(bstrErrDescription); }