2014-09-10 19 views
0

我需要一个应用程序来监视SQL Server作业。例如:我有CPU使用率图形,时间比例在14:00:200和14:20:000之间156.编号作业应该是seen.I想拍像this.I'm新秀programmer.Is它的东西可能对不起,我英文不好如何在C#中监控SQL Server作业

+0

你应该阅读[我如何问一个好问题?](http://stackoverflow.com/help/how-to-ask) – 2014-09-10 11:36:22

回答

2

你可以使用

SELECT 
    ja.job_id, 
    j.name AS job_name, 
    ja.start_execution_date,  
    ISNULL(last_executed_step_id,0)+1 AS current_executed_step_id, 
    Js.step_name 
FROM msdb.dbo.sysjobactivity ja 
LEFT JOIN msdb.dbo.sysjobhistory jh 
    ON ja.job_history_id = jh.instance_id 
JOIN msdb.dbo.sysjobs j 
    ON ja.job_id = j.job_id 
JOIN msdb.dbo.sysjobsteps js 
    ON ja.job_id = js.job_id 
    AND ISNULL(ja.last_executed_step_id,0)+1 = js.step_id 
WHERE ja.session_id = (SELECT TOP 1 session_id FROM msdb.dbo.syssessions ORDER BY agent_start_date DESC) 
AND start_execution_date is not null 
AND stop_execution_date is null; 

来源:http://sqlstudies.com/2013/09/05/a-t-sql-query-to-get-current-job-activity/

+1

您可能想要添加** WHERE ja.start_execution_date BETWEEN'2012-04-10 14:00:00'和'2014-09-10 14:20:00'**。 – Margus 2014-09-10 11:39:03

+0

是否有可能在图形中显示此值?以及如何?我可以获取这些值并将其显示在datagridview上,但对于chart而言我不太好.Chart也将在我的应用程序中 – 2014-09-10 12:17:55

+0

实际上超出了范围1个问题,但请看http://www.c-sharpcorner.com/UploadFile/mahesh/charting-in-wpf/ – Margus 2014-09-10 12:31:59