Error Handling

  • Hi All,

    I am using SQL Server 2000. When an error happens in my stored proc, the process exits from the line of the code where error occurs so there is no way of knowing what the error was. I have used code like:

    if @@error <> 0

    begin

    set @step = 'error description'

    goto err

    end

    but it is not working. Can you help?

    Thanks.

  • [font="Verdana"]

    goto err

    Ram, have you written err: at the end of SProc(i doubt), so that whenever you write GOTO it will switch to the error handling label? The code is seems ok. If possible, post the whole SProc.

    Mahesh

    [/font]

    MH-09-AM-8694

  • Mahesh,

    Thanks for your response. The err: label looks like following:

    err:

    print @Step

    I am debugging the Stored proc and stepping thru line by line. As soon as there is an error, it exists the stored proc and goes to the .net code. It should go to the err: label.

    Thanks.

  • [font="Verdana"]

    ...As soon as there is an error, it exists the stored proc and goes to the .net code...

    Are you handling errors at front end with Try Catch block? Not sure, but for time being just comment them and try.

    By the way, if possible post SProc and some code of .Net where you call the SProc and where it is switching in .Net code after the error occurs into SProc.

    Mahesh

    [/font]

    MH-09-AM-8694

  • Mahesh,

    Sorry I did not see your post earlier. The problem was that I am using Microsoft Applcation block and it was timing out. So as soon as it timed out, it exited the Stored Proc without going to the error label. Thank you for your time for looking into this.

  • Mahesh Bote (5/5/2008)


    [font="Verdana"]

    ...As soon as there is an error, it exists the stored proc and goes to the .net code...

    Are you handling errors at front end with Try Catch block? Not sure, but for time being just comment them and try.

    By the way, if possible post SProc and some code of .Net where you call the SProc and where it is switching in .Net code after the error occurs into SProc.

    Mahesh

    [/font]

    He's using SQL 2000. No Try/Catch blocks. (Not sure why this thread is in the SQL 2005 forum, but the first post says SQL 2000.)

    SQL Server errors usually give you the line number of the error in the error message. That might help.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • [font="Verdana"]

    GSquared (5/7/2008)


    Mahesh Bote (5/5/2008)


    [font="Verdana"]

    ...As soon as there is an error, it exists the stored proc and goes to the .net code...

    Are you handling errors at front end with Try Catch block? Not sure, but for time being just comment them and try.

    By the way, if possible post SProc and some code of .Net where you call the SProc and where it is switching in .Net code after the error occurs into SProc.

    Mahesh

    [/font]

    He's using SQL 2000. No Try/Catch blocks. (Not sure why this thread is in the SQL 2005 forum, but the first post says SQL 2000.)

    SQL Server errors usually give you the line number of the error in the error message. That might help.

    Thanks GSquared for updating me. I missed to read the post completely. My mistake. As the post was in SQL 2K5 forum, so I was under impression, the guy is using SQL 2K5. [/font]

    MH-09-AM-8694

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply