Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Server Agent Jobs – Displaying Status in an Application


SQL Server Agent Jobs – Displaying Status in an Application

Author
Message
mstjean
mstjean
SSC-Addicted
SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)

Group: General Forum Members
Points: 483 Visits: 2542
Re << Carrier pigeon has not happened yet, but we are still waiting...>>
It was only a matter of time....
http://news.bbc.co.uk/1/hi/world/africa/8248056.stm


When a co worker sent this to me I replied with

However it was found that when suitable security and data protection processes were included, the bird was squished by the chain mail.
Debate arose among the researchers when a splinter group opposed a plan to do a feasibility study using Kevlar-based chain mail—claiming CrocodileNet™® would have inherent security and data protection advantages.

CrocodileNet advocates pointed out that the Chicken-on-a-Stick/GPS interface used to guide the reptile worked flawlessly and minimized the 78% mortality rate in reception staff at the target site on data delivery. An additional faction claims these losses could be reduced by 37.2% if the rushed to production Chicken-on-a-Stick/GPS interface were to include the Croco-Snooze add on (consisting of a tranquilizer syringe that would be triggered when the GPS detected arrival at target site and/or in the reception area thereof), which had originally been part of the base specification but was dropped late during the rollout due to budgetary constraints.



Cursors are useful if you don't know SQL
mstjean
mstjean
SSC-Addicted
SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)

Group: General Forum Members
Points: 483 Visits: 2542
You need to tell the user the status of a job (sql job name is known) that was kicked off at a known date and time. Unless there's something else special going on, I don't think you need SSIS to get this done. (does your SSIS keep auto-refreshing your application page or something?)

I think you're better off using sysjobhistory and run_status to check job status...

The code below (turn it into a USP) will show you job/step details for a named job, run within the last n seconds (where n is set via @WithinTheLastNseconds). You could probably grab the exact time when the user kicked off the job so you could tighten this part up. Call the USP when the user clicks on a "refresh status" button or similar. You may want more or less detail; that's your call.

I used a variation of this when I had a 30-40 ETL scripts (as separate sql jobs) to run. They had to run without overlapping, so I created a sql job that would run each job-- and at 30 second intervals, check to see if that job had completed before going on to the next.




DECLARE @jname varchar(200);SET @jname = 'PUT YOUR SQL JOB NAME HERE'         -- faked parm
DECLARE @WithinTheLastNseconds int;SET @WithinTheLastNseconds = 6000 -- restrict to only jobs within this many seconds; recommended parm

DECLARE
@yyyymmddint int,
@hhmmssch char(8),
@hhmmssint int

SELECT @yyyymmddint = CONVERT(varchar(20),getdate(),112),@hhmmssch = CONVERT(char(8),DATEADD(second,-@WithinTheLastNseconds,getdate()),8)
SET @hhmmssint = SUBSTRING(@hhmmssch,1,2) + SUBSTRING(@hhmmssch,4,2) + SUBSTRING(@hhmmssch,7,2)


select sj.name,
jh.instance_id,
jh.run_date,
jh.run_time,
jh.step_id,
jh.step_name,
jh.message,
jh.run_status,
CASE jh.run_status
WHEN 0 THEN 'Failed'
WHEN 1 THEN 'Succeeded'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Canceled'
WHEN 4 THEN 'In progress'
ELSE '-abnormal-'
END as run_status_desc
,jh.*
from msdb.dbo.sysjobhistory jh
inner join msdb.dbo.sysjobs sj ON jh.Job_ID = sj.Job_ID
where
jh.run_date = @yyyymmddint
and jh.run_time >= @hhmmssint
and sj.name=@jname
order by
sj.name,
jh.instance_id




Cursors are useful if you don't know SQL
brettveenstra
brettveenstra
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 30
You might want to look at msdb.dbo.sp_get_composite_job_info instead, single row per job, gives you running status.
core-909671
core-909671
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 116
I created a stored proc to pull job status (like the article), and it works great in the test environment. As soon as I pushed it to production I get the message "select permissions was denied on object 'sys.jobs'".

I'm stumped on a safe way to show the job status.
James O.
James O.
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 52
I was naively trying to run the sp_stop_job in a maintenance plan, which of course, was throwing errors if the job was not running. Thanks to your article, I was able to now craft a simple sp to check the status and only stop it if it's running. Thanks!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search