all groups > sql server programming > november 2007 >
You're in the

sql server programming

group:

Job Activity Monitor tool


Job Activity Monitor tool Tom
2/28/2007 7:24:14 AM
sql server programming: can someone tell me what table or stored procedure that the Job Activity tool
uses to show the activity for the jobs on the db server? I'm asking because
I'm creating a web form that list all db servers on the network and all the
jobs under SQL Server Agent, and I need to show the status of the job that is
running that was selected from the web form.

Example:
when the user selects a job they can run it, but I want to show this on my
web form
Jobname
Step 1 processing. . . .
Step 1 completed Succeeded

Step 2 processing. . . . .
Step 2 completed Succeeded

and so one, I noticed that the Job Activity is showing this information. So
how can I use the job activity monitor on my web form or use the stored
procedure or table that the tool is using?
Re: Job Activity Monitor tool Tom
2/28/2007 7:50:30 AM
Correct, I'm using SQL 2005 though I don't see sysjobs_view in there, I do see
sp_help_jobactivity and sp_help_jobhistory but not the jobs_view.

I'm able to run the job fine, I just want to show the samething that the job
activity monitor is on my web form

[quoted text, click to view]
Re: Job Activity Monitor tool Aaron Bertrand [SQL Server MVP]
2/28/2007 10:33:52 AM
I assume SQL Server 2005? I do something similar using these objects:

msdb..sysjobs_view
msdb..sysjobactivity
msdb..sysjobhistory

--
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006





[quoted text, click to view]

Re: Job Activity Monitor tool Aaron Bertrand [SQL Server MVP]
2/28/2007 10:59:18 AM
[quoted text, click to view]

Are you sure? I have it on my systems, here is the definition:

CREATE VIEW sysjobs_view
AS
SELECT jobs.job_id,
svr.originating_server,
jobs.name,
jobs.enabled,
jobs.description,
jobs.start_step_id,
jobs.category_id,
jobs.owner_sid,
jobs.notify_level_eventlog,
jobs.notify_level_email,
jobs.notify_level_netsend,
jobs.notify_level_page,
jobs.notify_email_operator_id,
jobs.notify_netsend_operator_id,
jobs.notify_page_operator_id,
jobs.delete_level,
jobs.date_created,
jobs.date_modified,
jobs.version_number,
jobs.originating_server_id,
svr.master_server
FROM msdb.dbo.sysjobs as jobs
JOIN msdb.dbo.sysoriginatingservers_view as svr
ON jobs.originating_server_id = svr.originating_server_id
WHERE (owner_sid = SUSER_SID())
OR (ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0) = 1)
OR (ISNULL(IS_MEMBER(N'SQLAgentReaderRole'), 0) = 1)
OR ( (ISNULL(IS_MEMBER(N'TargetServersRole'), 0) = 1) AND
(EXISTS(SELECT * FROM msdb.dbo.sysjobservers js
WHERE js.server_id <> 0 AND js.job_id = jobs.job_id)))

[quoted text, click to view]

And you can that using queries against these three objects (I don't use the
sp_help procedures you mention).

--
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006

Re: Job Activity Monitor tool Tibor Karaszi
2/28/2007 4:33:14 PM
I suggest you use SMO for this. Check out the namespace:
Microsoft.SqlServer.Management.Smo.Agent

And classes etc like:
Job Class
.currentRunStatus
JobExecutionStatus Enumeration

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/


[quoted text, click to view]

Re: Job Activity Monitor tool JFB
3/1/2007 12:00:00 AM
Hi Aaron,
I can see this objects and I got the report of the jobs and the date time
when suppost to run but how can I get if the last time the job success or
failed?
select v.originating_server, v.name, v.job_id, Max(a.run_requested_date) as
requested_date,

Max(a.next_scheduled_run_date) as next_run_date

from msdb.dbo.sysjobs_view v

inner join msdb.dbo.sysjobactivity a

on v.job_id = a.job_id

where v.enabled = 1

group by v.originating_server, v.name, v.job_id

Tks

JFB



[quoted text, click to view]

Re: Job Activity Monitor tool Aaron Bertrand [SQL Server MVP]
3/1/2007 10:59:11 AM
sysjobhistory will have run_status = 0 AND [message] LIKE 'The job failed.%'
where step_id = 0 and job_id = x.

--
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006




[quoted text, click to view]

Re: Job Activity Monitor tool JFB
3/1/2007 9:09:57 PM
Got it Aaron....Tks

JFB

[quoted text, click to view]

RE: Job Activity Monitor tool NormK
11/14/2007 10:51:45 AM
[quoted text, click to view]

"sysjobhistory will have run_status = 0 AND [message] LIKE 'The job failed.%'
where step_id = 0 and job_id = x."

Does run_status correlate with the return code of sp_help_jobactivity? If so, then run_status = 0 indicates success. Is there a query I can run that will give a numeric failure code instead of relying on the "failed" string in the message field?


From http://www.developmentnow.com/g/113_2007_2_0_0_938450/Job-Activity-Monitor-tool.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button