views:

598

answers:

1

Hello everyone,

I am using SQL Server 2008 and I am writing a SQL Server Agent Job. In my Job, there are 3 steps and in each step I will execute a store procedure. I noticed that in default Notification setting, it write information to Windows event log only when it fails.

My question is, any easy solutions to write both success and fail information of each step to windows event log or somewhere to easily monitored? My job runs daily and I need the information for both success and fail to ensure my job runs.

thanks in advance, George

+2  A: 

The Notifications in the job properties also allows you to pick an action when the job succeeds! That button to the right is a dropdown, really - you can pick various outcomes, e.g. write to event log when it fails, and send an e-mail when it succeeds.

If you choose the "If job completes" option, I believe the action (write to event log, send e-mail etc.) will be triggered in both cases - success and failure.

Marc

PS: maybe this here helps?
http://msdn.microsoft.com/en-us/library/ms191130.aspx

If you want to notify an operator by e-mail, check E-mail, select an operator from the list, and then select one of the following:

* When the job succeeds to notify the operator when the job completes successfully.
* When the job fails to notify the operator when the job completes unsuccessfully.
* When the job completes to notify the operator regardless of completion status.
marc_s
Thanks Marc, "write a "success" message to a job log table in your SQL Server database somewhere" -- you mean I create another table manually and insert into this table execution status manully from store procedure to indicate success or fail? No built-in solutions? :-)
George2
See my edits- there are plenty of ways you can notify of job success, too.
marc_s
"the Notifications in the job properties also allows you to pick an action when the job succeeds" -- yes, but no way to select both success and fail. I need both information to indicate my jobs actually runs in the designed schedule. :-)
George2
Yes, I think that's the "when job completes" option
marc_s
That will trigger the action when the job completes - whether it succeeded or failed.
marc_s
Yes, Marc. You are correct. I have tested it. But seems no document clearly says complete includes both success and fail information.
George2
Do you have such documents to explain the meaning of complete?
George2
Thanks Marc, any ideas to make one storeprocedure fail? I want to make some more testing about exactly what complete means. :-)
George2
"notify the operator regardless of completion status" -- means we can never know whether success or fail. Hard to debug in real product systems. Any ideas? :-(
George2
No - it means it will be notified both in case of a success and in case of a failure - the message in the notification will be clear as to whether it succeeded or failed! :-)
marc_s
To make a stored proc fail, you can call RAISERROR in the middle of it: RAISERROR (N'This procedure failed on purpose', 10, -99);
marc_s
Thanks Marc, I have tested it works for both success and fail!
George2
Marc, I have tried to call RAISE ERROR RAISERROR (N'This procedure failed on purpose', 10, 10), but in event log it is marked as success, any ideas what is wrong?
George2