Friday, March 23, 2012

Job running status

In SQL 2000, go to Management, than Jobs, you will see a list of all jobs and their running status. I would like to programmatically display the same on my web page. I can call sysjobs table to get the jobs and use sysjobschedules to determine whether it's been scheduled or not. Then use sysjobhistory to obtain their running history. But how and where do I get the Next Run Date information? Is this calculated or stored somewhere?

Can anyone give me some help on how to work with sysjobs, sysjobschedules, and sysjobhistory tables? All I am trying to do is to build a web-based app that does the same thing as the Enterprise Manager is doing - create and schedule a job, and monitor the job status.

Thanks a lot!

Penn

Performing query directly to system tables is not recommended, as the schema of system tables/views may change even between different builds. Instead, you can use some system procedures to get detailed information about agent jobs, for example:

exec msdb..sp_help_job @.job_name='Expired subscription clean up'

So you can call such system procedures from your code using SqlDataAdapter and then fill the result sets into DataSet for future using. For more information about system procedures, please refer to:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_00_519s.asp

No comments:

Post a Comment