What's the best way to handle DB errors when using ADO?

From: Joseph Miranda (jalexm_at_ubbi.com.br)
Date: 10/16/04

  • Next message: Bryan Dayton: "Re: Problem with MS SQL + ADO + BLOB image"
    Date: 15 Oct 2004 20:25:07 -0700
    
    

    Hello,
    I'm a beginner using Delphi/ADO and I'm creating a simple DB app using MS-Access tables.
    Now I need to handle errors like key violation, invalid field values, fields that must have a value, etc. and show friendly error messages to the user. ADO/MS-Access messages are not friendly in my opinion.

    First, I tried OnPostError event handler.
    But I'm not sure if OnPostError event is fired only by a key violation error. If another error fires this event, my message to the user will not be correct.
    In fact, I don't know how to detect exactly what kind of error happened using OnPostError.
    The same problem with OnDeleteError, OnEditError, etc.

    So, I tried to write a global exception handler to trap EDatabaseError and check some properties of ADOConnection Errors. The properties SQLState and NativeNumber change their values according to the errors.
    But I'm not sure if these things can be used for this purpose.

    I can't use try...except blocks because I'm using DBGrids to edit/insert/post operations.

    Please, can you help me?
    Thanks


  • Next message: Bryan Dayton: "Re: Problem with MS SQL + ADO + BLOB image"