Link to home
Start Free TrialLog in
Avatar of motioneye
motioneyeFlag for Singapore

asked on

How to trace procedure errors efficiently in sql2008

I have a stired procedure which have written very long and its also use to execute another procedures within a procedure. now this procedure doesn't seems work fine and I need to trace at which execution the procedure failed to run.
This procedure define to be run on sql jobs, but  nothing were written when I try  to enable the error log in sql jobs.

any best way to find where out the procedure failed within the job ?
Avatar of 25112
25112

you should put try/catch in your code to catch the error.. here is an example..
BEGIN TRY
    SELECT 2+'A'
END TRY
BEGIN CATCH
    SELECT ERROR_NUMBER() AS ErrorNumber,ERROR_SEVERITY() AS ErrorSeverity,ERROR_STATE() as ErrorState,ERROR_PROCEDURE() as ErrorProcedure,
        ERROR_LINE() as ErrorLine,ERROR_MESSAGE() as ErrorMessage;
END CATCH

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of 25112
25112

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial