Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to trace procedure errors efficiently in sql2008

Posted on 2011-09-19
3
236 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 500 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 500 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

839 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