Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-09-21
7
Medium Priority
?
214 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
[X]
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
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this article I will describe the Copy Database Wizard 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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

609 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