Getting my custom error message from SQL 2000 sp

I have sp with the following pseudocode ...

    BEGIN TRANSACTION
            set @errorLocation='Deleting Permissions'
            DELETE [tblUsrPermissions]
            WHERE
                lngUserID = @lngUserID
            if @@error>0
            begin
                goto roll_back
            end

            COMMIT TRANSACTION
            set @errorLocation='' --clear error messages
            select @errorLocation --return success
    return
roll_back:
    IF @@TRANCOUNT > 0
        ROLLBACK TRANSACTION -- there were errors, rollback
    select @errorLocation 

      

I am using SQL sqlclient sql datareader and I am getting exeception in code when I call ExecuteScalar function - error occurs during my delete operation in sp.

I want to get my own error message instead of an exception. What can I do?

0


source to share


2 answers


use raiserror to pass your error to the client. note that depending on the severity of the erorr, your raiserror message will never be harmed. so for a more complete answer, please list the original error you get and where you get it.



+1


source


If you are using SqlServer 2005 or higher, put the code inside the TRY block and then call RAISERROR in the catch block



0


source







All Articles