Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to trace procedure errors efficiently in sql2008

Posted on 2011-09-19
3
Medium Priority
?
243 Views
Last Modified: 2012-05-12
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 ?
0
Comment
Question by:motioneye
  • 3
3 Comments
 
LVL 5

Expert Comment

by:25112
ID: 36561120
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

0
 
LVL 5

Accepted Solution

by:
25112 earned 2000 total points
ID: 36561131
ERROR_MESSAGE() is the key which will tell you what the problem is..

if you try your code in several segments of the proc, it may help you to isolate the area where it is failing.
0
 
LVL 5

Assisted Solution

by:25112
25112 earned 2000 total points
ID: 36561137
another option is to manually run each segment of the proc by passing the parameters.. this will be manual troubleshooting..
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

916 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