Solved

How to handle the error when a step in the SQL job fails

Posted on 2011-09-21
7
205 Views
Last Modified: 2012-05-12
I created a job with about 4 steps that process data and uses ftp to send data to our customer.

If the job fails during any step , I want to log that into  a table in the database with the error which caused the step to fail.

0
Comment
Question by:Bkuniyil
  • 3
  • 3
7 Comments
 
LVL 17

Expert Comment

by:dbaSQL
Comment Utility
I would just create an Error table to house the error functions, and insert them from the TRY/CATCH, similar to what's in this link:
http://www.sqlservernation.com/home/using-trycatch-in-sql-server.html


even better, the uspLogError procedure writes error details into the ErrorLog table.  you can use this within each of your jobs steps as the action upon failure.  then you can send an email with the error_line or error_number, with the 'JobName Failure' in the subject ine.

http://msdn.microsoft.com/en-us/library/ms179296.aspx
0
 

Author Comment

by:Bkuniyil
Comment Utility

  Actually the job step does not execute a stored procedure. It executes an SSIS package.  When the package returns with an exit code other than 0 it is a failure. Hence the job fails . I need to trap this error and log into the database.

Experts, could you please help me in achieving this.
0
 
LVL 39

Expert Comment

by:lcohan
Comment Utility
Assuming it's a SQL job you can do that directly in the job step under the "Advanced" like in the attached picture - either log to a table and/or include step output in the history and you can also send emil notifications on failure. If you need to log from the batch (cmd file) that does the FTP then you may need additional code and run SQL command shell to populate the table.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 39

Expert Comment

by:lcohan
Comment Utility
Ok, in that case the SSIS step that is executed need to include a BEGIN/TRY/CATCH set of SQL commands as "dbasql" suggested. Also you can configure the SSIS to do the Logging including in the Event long on that server.

Integration Services Log Providers

http://msdn.microsoft.com/en-us/library/ms140246(v=sql.90).aspx
0
 

Author Comment

by:Bkuniyil
Comment Utility

   The requirement is to log the error in the table created in the database.  I guess the "Log to table"  option under the Notifactions  does not help me here.  Also the SSIS package is used to execute a batch file , so i would not be able to include a  TRY/CATCH there.
0
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
Comment Utility
Of course you can easily do that - from the batch file you execute commands against SQL to populate that table or anything else via SQLCMD utility:

sqlcmd Utility Tutorial
http://msdn.microsoft.com/en-us/library/ms170207(v=SQL.90).aspx
0
 

Author Closing Comment

by:Bkuniyil
Comment Utility
The solution partially resolved my problem.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now