Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

SQL Server Agent Jobs – Displaying Status in an Application Expand / Collapse
Author
Message
Posted Wednesday, September 16, 2009 10:40 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 2:30 PM
Points: 436, Visits: 2,198
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
Post #789132
Posted Wednesday, September 16, 2009 12:33 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 2:30 PM
Points: 436, Visits: 2,198
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
Post #789211
Posted Wednesday, September 16, 2009 12:40 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, October 26, 2012 10:31 AM
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.
Post #789214
Posted Wednesday, January 20, 2010 8:15 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, December 02, 2010 8:45 AM
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.
Post #850970
Posted Thursday, June 10, 2010 8:27 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 10, 2011 12:07 PM
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!
Post #935393
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse