EarthWeb
Developer.com
Find:
 


SEARCH TECHCRAWLER -----
CodeGuru Links
Visual Basic
Visual C++

Discussion Boards
Book Reviews
Newsletters (subscribe)
Newsletters (archived)
Guru Columns
  • Nothing but .NET
  • Bugs in the Machine
  • The Shell Game
  • Into the IUnknown
  • The Working Class Programming
  • Tempting Templates
  • Programming in the Real World
  • Article Sections
    ATL COM ActiveX
    atl com activex
    shell programming
    C++
    algorithms & formulas
    c++ & mfc
    date & time
    string
    Controls
    button control
    combobox
    edit control
    imagelist control
    listbox control
    listview control
    menu
    other controls
    property sheet
    rich edit control
    static control
    status bar
    toolbar
    treeview control
    Database
    database
    Frameworks
    ui & printing frameworks
    Graphics & Multimedia
    bitmaps & palettes
    directx
    gdi
    multimedia
    opengl
    Internet & Networking
    ie programming
    internet protocols
    isapi
    network protocols
    Visual Studio
    add-ins & macros
    editor tips
    Windows Programming
    ce
    clipboard
    dll
    file & folder
    help systems
    printing
    win32
    system
    Windows & Dialogs
    console
    dialog
    docking window
    doc/view
    splitter
    Interact
    Newsletters
    Guestbook
    Recommend Us!
    About Us




    EarthWeb Sites:
    IT Management
    Networking & Telecommunications
    IT Jobs
    Software Development
    Web Development
    Hardware & Systems
    Community & SIGs
    EarthWeb Worldwide
       

    Error Handling with ADO


    This article was contributed by Waleed Darwish.

    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!
      try
      {
         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 )
      {
         TRACE( "*** UNABLE TO LOG EXCEPTION ***" );
         e->Delete();
      }
      catch(...)
      {
         TRACE( "*** UNABLE TO LOG EXCEPTION ***" );
      }
    
      pErrors->Release();
      pError->Release();
    
      return hr;
    }
    

    History

    Date Posted: June 19, 1999

    Comments:

    Add Comment

       

    Give them a visit Click Here!

    Click Here!

    Get the Answers You Need!
    Incentive-based, question & answer Marketplace. The first 5,000 members receive $12 credit! Try it! Knowledge Market.

    For tons of Windows technology resources, check out the Windows Programming directory.

    Target your Technical searches with
    TechCrawler

    Sweepstakes:
    Here's your chance to win Windows 2000 Professional. EarthWeb's sweepstakes runs through July 2. Click here to enter.

    Give them a visit Click Here!

    Click Here!


    ★ wanayoo — archive 1999 http://codeguru.earthweb.com/mfc_database/ErrorHandlingWithADO.shtmlNouvelle recherche | Portail wanayoo

    Home About Us Subscribe Contact Us
    Use of this site is subject to certain Terms & Conditions.
    Earthweb's statement regarding our users' right to privacy.
    Copyright ©1996-2000 EarthWeb Inc.. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited.