Error Handling with ADO

I'm new to ADO and I searched for a piece of code to handle errors, I found the following code snippet in an article and wanted to share it with other ADO developers that might be looking for something similar.

The following function (LogAdoErrorImport) can be called from any catch block in your program.

// Obtain information from the Errors Collection
HRESULT LogAdoErrorImport(_ConnectionPtr pConn)
  ErrorsPtr   pErrors;
  ErrorPtr    pError;
  CString     strTmp;
  HRESULT     hr = (HRESULT) 0L;
  long        nCount;

  // Don't have an un-handled exception in the handler that
  // handles exceptions!
     pErrors = pConn->GetErrors();

     nCount = pErrors->GetCount();

     for( long i = 0; (!FAILED(hr)) && (i < nCount); i++ )
        TRACE( "\t Dumping ADO Error %d of %d", i+1, nCount );

        hr = pErrors->get_Item((_variant_t)((long)i), &pError );

        _bstr_t bstrSource     ( pError->GetSource()      );
        _bstr_t bstrDescription( pError->GetDescription() );
        _bstr_t bstrHelpFile   ( pError->GetHelpFile()    );
        _bstr_t bstrSQLState   ( pError->GetSQLState()    );

        TRACE( "\n Number      = %ld", pError->GetNumber()       );
        TRACE( "\n Source      = %s",  (LPCTSTR) bstrSource      );
        TRACE( "\n Description = %s",  (LPCTSTR) bstrDescription );
        TRACE( "\n HelpFile    = %s",  (LPCTSTR) bstrHelpFile    );
        TRACE( "\n HelpContext = %ld", pError->GetHelpContext()  );
        TRACE( "\n SQLState    = %s",  (LPCTSTR) bstrSQLState    );
        TRACE( "\n HelpContext = %ld", pError->GetHelpContext()  );
        TRACE( "\n NativeError = %ld", pError->GetNativeError()  );
  catch( CException *e )


  return hr;



  • Require information

    Posted by Legacy on 05/08/2003 12:00am

    Originally posted by: Ali Haider

    I need some information, how to edit a ado recordset.
    I am new one in programming feild.
    Please help me.

  • error message when using large database

    Posted by Legacy on 06/25/2002 12:00am

    Originally posted by: Josh

    Having a problem executing a query (under ADO recordset open method).
    Using the error handling code, I get the description message:
    "Not enough space on temporary disk"

    My database is large: 390MB --> consisting mainly of one large table with 90 million+ records.
    The query I execute should return about 15 million records.

    After a few hours of processing my ADO code bombs out and get the above error logged.
    The query works as expected on smaller databases.

    I am confused because I have more than 10 GIG of memory on my hard drive. Is it possible this is all being filled?

    Any insight would be appreciated!

  • MFC Programmer's Sourcebook

    Posted by Legacy on 09/06/2001 12:00am

    Originally posted by: G.Ravi Kiran

    How to find a transaction already started using ADO

  • how to catch the error infomation

    Posted by Legacy on 08/29/2001 12:00am

    Originally posted by: emily

    i use ado to connect a datasource using the following statement:
    but when the datasource "dd" is not exist,a fatal error will occur.would you kindly tell me how to avoid it?

  • How to ExecuteSQL and commit transactions using ADO

    Posted by Legacy on 06/01/2001 12:00am

    Originally posted by: Sajjad Hussain

    I'm using ADO control. I want to execute SQL statements through this control. I can navigate records, delete, update and add new records. Infact I have to delete a set of records from a table in .mdb under certain condition. For this I have to Execute SQL which I don't know how to execute. How to commit transactions through ADO.

  • nice/rough

    Posted by Legacy on 04/08/2001 12:00am

    Originally posted by: shahbaz khan

    Good for some of the ruthless user like us.Thanx.

  • I am new in database interfaces using ADO and Visual C++

    Posted by Legacy on 01/26/2001 12:00am

    Originally posted by: Wael Eletlbany

    hello everyone
    Can anyone tell me about a website, book, or tutorial about how to connect a database to a Visual C++ interface using ADO. Given that the database is fully relational with multiple tables done using Access 2000. I am saying multiple table because I've seen an example for a single table databse.
    Thank you

  • Unhandled Exception when using ADO

    Posted by Legacy on 09/29/1999 12:00am

    Originally posted by: Ovais Khan

    Well i use ADO to convert my code from DAO. Most of the time it works fine but can anyone tell me which exception is raised by the ADO object. like DBException is raised by DAO in MFC. _com_error exception is not raised and i do not get the error description in some cases.


  • Unknown error

    Posted by Legacy on 08/11/1999 12:00am

    Originally posted by: Simon Wang

    In my program, I got a com error message said "Unknown error 0x800A0E78". Does anybody know what causes this? and what it means? Thanks!

  • Some bugs

    Posted by Legacy on 07/06/1999 12:00am

    Originally posted by: Douglas Huang

    This function is taken from one of the MSDN articals.
    However, when there is no error object, the statements
    cause an error.
    Who can tell me why?


    Douglas Huang

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Today, users, applications, and data exist in more places than ever before, creating an unprecedented challenge for IT. How can IT achieve the flexibility and agility it needs to offer multiple types of applications in multiple locations? To better serve business demands for information everywhere, enterprises must develop new strategies for optimizing multiple kinds of networks. Read this white paper to learn how hybrid networks provide an unprecedented level of network dynamism, enterprise agility, and the …

  • Data integrity and ultra-high performance dictate the success and growth of many companies. One of these companies is BridgePay Network Solutions, a recently launched and rapidly growing financial services organization that allows merchants around the world to process millions of daily credit card transactions. Due to the nature of their business, their IT team needed to strike the perfect balance between meeting regulatory-mandated data security measures with the lowest possible levels of latency and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date