failing a sql job upon send mail task
Hi,
Is there an easy way some setting perhaps that I can fail a sql job after successfully completing a mail task in SSIS?
Thanks,
Phil
August 7th, 2012 12:59pm
Hi Phil,
A SQL job is what? A Execute SQL Statement? In SQL Server?
In general RAISE ERROR T-SQL is the one to use to intentionally fail any SQL in SQL Server.
Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
August 7th, 2012 2:16pm
Wait, after SUCCESSFULLY sending an email you want a FAILURE status?
Seems a bit backwards.
Perhaps you could enlighten us with the overall process of what you are doing and how and when you want people notified from your SSIS package. Seems there might be a better way to handle the whole overall operation.Todd C - MSCTS SQL Server 2005, MCITP BI Dev 2008 Please mark posts as answered where appropriate.
August 7th, 2012 2:27pm
Set the result to 'Failure' as below in the Script task that takes its precedence constraint from the mail task:
Dts.TaskResult = ScriptResults.Failure
Doing this will fail your package which in turn will fail your job.
Free Windows Admin Tool Kit Click here and download it now
August 7th, 2012 3:32pm
Jay'D - where can I do this? In the actual 'send mail task'?
The reason I want to do this is I want to email a failure email and then fail the job so the job will automatically run again (you can set that up in the job properties of any job).
Thanks,
Phil
August 7th, 2012 4:48pm
I figured it out. Thanks Jay'D.
Create a script task AFTER the send mail and do this:
public void Main()
{
// TODO: Add your code here
Dts.TaskResult = (int)ScriptResults.Failure;
}
Free Windows Admin Tool Kit Click here and download it now
August 7th, 2012 4:56pm
Exactly. Good to know that what you needed.!
August 7th, 2012 5:18pm