[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-09-21
7
Medium Priority
?
216 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
ID: 36577234
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
ID: 36580520

  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 40

Expert Comment

by:lcohan
ID: 36580551
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:lcohan
ID: 36580559
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
ID: 36580753

   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 40

Accepted Solution

by:
lcohan earned 1000 total points
ID: 36581029
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
ID: 37070049
The solution partially resolved my problem.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

831 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