How to use error info in data access layer to trigger message to user

Posted on 2006-04-20
Last Modified: 2010-04-23
I have a delete method for a table that doesn't work when the key from that table is associated with records in another table. When the user attempts to delete a one of these records, a sql exception number 547 is thrown in the data access layer. When this error number is thrown, I want to notify the user of what is going on. I figured I could just store the error number in a session variable and check for it when the code got back to the procedure that called the delete method in the data access layer, but I can't create a session variable there - I guess because it's a seperate class. Anyway, how can I get the error number back to the calling procedure so I can check for it? I'm figuring there is some standard way that people use that I'm not aware of. Thanks.

Question by:Feyo
    LVL 10

    Accepted Solution

    best you can use exceptions.

    throw an exception from the DAL part.
    catch the exception in the called procedure.
    display the message

    you can use the session varibales by httpcontext . but it is not advisable


    LVL 4

    Author Comment

    Should I be able to catch that exception where I call the procedure? For some reason, it's not catching.
    LVL 10

    Expert Comment

    did u directly call the DAL?
    can u post a sample code?
    LVL 4

    Author Comment

    This does seem to work. Thanks.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now