Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. ADO Errors

ADO Errors

Scheduled Pinned Locked Moved Database
c++databasesql-serversysadminhelp
5 Posts 2 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Magnus_
    wrote on last edited by
    #1

    Im using ADO to access an SQL server and everything is working ok except for when an error occurs. Then the description and source properites in the error object is *always* null. The native error number is how it should be. Anyone got a clue what could cause this? (we also access the db with MFC and ODBC and there the description is correct) /Magnus

    R 1 Reply Last reply
    0
    • _ _Magnus_

      Im using ADO to access an SQL server and everything is working ok except for when an error occurs. Then the description and source properites in the error object is *always* null. The native error number is how it should be. Anyone got a clue what could cause this? (we also access the db with MFC and ODBC and there the description is correct) /Magnus

      R Offline
      R Offline
      Rashid Thadha
      wrote on last edited by
      #2

      Send your code snippet so we can have a look at what you are doing wrong

      _ 1 Reply Last reply
      0
      • R Rashid Thadha

        Send your code snippet so we can have a look at what you are doing wrong

        _ Offline
        _ Offline
        _Magnus_
        wrote on last edited by
        #3

        Here is the codesnippet used to get the error. The _ConnectionPtr passed in is either the connection pointer used to execute the command or gotten from _RecordsetPtr->GetActiveConnection() NativeError contains a valid number as said but all strings are NULL. void EmitError(_ConnectionPtr piCon) { if(piCon == NULL) return; ErrorsPtr ptrErrors = piCon->Errors; if(ptrErrors == NULL) return; long lCount = ptrErrors->Count; ErrorPtr ptrError = NULL; CString sError; for(long n = 0; n < lCount; n++) { ptrError = ptrErrors->GetItem(n); if(!(ptrError == NULL)) { LogEmit("%s\nState: %s, Native: %d, Source: %s\n\n", (LPCTSTR)_bstr_t(ptrError->GetDescription()), (LPCTSTR)_bstr_t(ptrError->GetSQLState()), ptrError->NativeError, (LPCTSTR)_bstr_t(ptrError->GetSource()) ); } } } /Magnus

        R 1 Reply Last reply
        0
        • _ _Magnus_

          Here is the codesnippet used to get the error. The _ConnectionPtr passed in is either the connection pointer used to execute the command or gotten from _RecordsetPtr->GetActiveConnection() NativeError contains a valid number as said but all strings are NULL. void EmitError(_ConnectionPtr piCon) { if(piCon == NULL) return; ErrorsPtr ptrErrors = piCon->Errors; if(ptrErrors == NULL) return; long lCount = ptrErrors->Count; ErrorPtr ptrError = NULL; CString sError; for(long n = 0; n < lCount; n++) { ptrError = ptrErrors->GetItem(n); if(!(ptrError == NULL)) { LogEmit("%s\nState: %s, Native: %d, Source: %s\n\n", (LPCTSTR)_bstr_t(ptrError->GetDescription()), (LPCTSTR)_bstr_t(ptrError->GetSQLState()), ptrError->NativeError, (LPCTSTR)_bstr_t(ptrError->GetSource()) ); } } } /Magnus

          R Offline
          R Offline
          Rashid Thadha
          wrote on last edited by
          #4

          use exception handling e.g.

          try
          {
          HRESULT hr = piCon->....;
          if (FAILED(hr))
          _com_issue_error(hr);

          }
          catch(_com_error& e)
          {
          CString sBuff = GetErrorDescription(e);
          AfxMessageBox(sBuff);
          return;
          }
          catch(...)
          {
          AfxMessageBox("Unknown Error Occured");
          return;
          }

          CString GetErrorDescription(_com_error& e)
          {
          _bstr_t bstrSource(e.Source());
          _bstr_t bstrDescription(e.Description());
          _TCHAR szTemp[1024];

          CString strInfo ;
          wsprintf(szTemp, \_T("Message : %s\\n"), e.ErrorMessage());
          strInfo = szTemp;
          wsprintf(szTemp, \_T("Code : 0x%08lx\\n"), e.Error());
          strInfo += szTemp;
          wsprintf(szTemp, \_T("Source : %s\\n"), bstrSource.length() ? (LPCTSTR)bstrSource : \_T("null"));
          strInfo += szTemp;
          wsprintf(szTemp, \_T("Description : %s\\n"), bstrDescription.length() ? (LPCTSTR)bstrDescription : \_T("null"));
          strInfo += szTemp;
          
          return strInfo;
          

          }

          :cool:

          _ 1 Reply Last reply
          0
          • R Rashid Thadha

            use exception handling e.g.

            try
            {
            HRESULT hr = piCon->....;
            if (FAILED(hr))
            _com_issue_error(hr);

            }
            catch(_com_error& e)
            {
            CString sBuff = GetErrorDescription(e);
            AfxMessageBox(sBuff);
            return;
            }
            catch(...)
            {
            AfxMessageBox("Unknown Error Occured");
            return;
            }

            CString GetErrorDescription(_com_error& e)
            {
            _bstr_t bstrSource(e.Source());
            _bstr_t bstrDescription(e.Description());
            _TCHAR szTemp[1024];

            CString strInfo ;
            wsprintf(szTemp, \_T("Message : %s\\n"), e.ErrorMessage());
            strInfo = szTemp;
            wsprintf(szTemp, \_T("Code : 0x%08lx\\n"), e.Error());
            strInfo += szTemp;
            wsprintf(szTemp, \_T("Source : %s\\n"), bstrSource.length() ? (LPCTSTR)bstrSource : \_T("null"));
            strInfo += szTemp;
            wsprintf(szTemp, \_T("Description : %s\\n"), bstrDescription.length() ? (LPCTSTR)bstrDescription : \_T("null"));
            strInfo += szTemp;
            
            return strInfo;
            

            }

            :cool:

            _ Offline
            _ Offline
            _Magnus_
            wrote on last edited by
            #5

            I do use exception handling, thats from where a try to get the ado-errors. The problem is not catching the error but that the description field is NULL. I can get the HRESULT, native error,.. but that are not very friendly messages. I dont think the code that tries to dig out the error is to blame here, the problem must lie somewhere else,.......and i dont have a clue where. :( /Magnus

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups