Sunday, February 19, 2012

How to know a Job Status from Stored Procedure

To execute a job from VB, I use stored procedure with T-SQL :

EXEC sp_start_job @.job_name = 'DTSName'

>From BOL, I know that procedure return 0 (success) or 1 (failure), but
that's only to tell user that job successfully started, right?
What I need is how to know is that job have executed successfully or
failed, so if success i will execute another code.

Please help me, thanksSee sp_help_job in Books Online. Alternatively, you could use SQL-DMO
from VB to get the CurrentRunStatus and/or LastRunOutcome property of
the Job object. Another option would be to add more steps to the job
itself, so that if the first step fails, it runs your extra code.

Simon|||But when I have execute sp_help_job if i don't know the job was
finished or not?|||The current_execution_status column tells you if the job is running;
the last_run_outcome columns tells you what happened the last time the
job finished.

If you want something to happen only when the job succeeds (or fails),
then it might be easiest to add another job step, as I mentioned. Then
you don't have to keep checking the job status from the client.

Simon

No comments:

Post a Comment