Re-running SSRS subscription jobs that have failed
Posted
by Rob Farley
on SQL Blog
See other posts from SQL Blog
or by Rob Farley
Published on Thu, 18 Mar 2010 03:51:41 GMT
Indexed on
2010/03/18
4:01 UTC
Read the original article
Hit count: 645
Reporting Services
|sql
Sometimes, an SSRS subscription for some reason. It can be annoying, particularly as the appropriate response can be hard to see immediately. There may be a long list of jobs that failed one morning if a Mail Server is down, and trying to work out a way of running each one again can be painful. It’s almost an argument for using shared schedules a lot, but the problem with this is that there are bound to be other things on that shared schedule that you wouldn’t want to be re-run.
Luckily, there’s a table in the ReportServer database called dbo.Subscriptions, which is where LastStatus of the Subscription is stored. Having found the subscriptions that you’re interested in, finding the SQL Agent Jobs that correspond to them can be frustrating.
Luckily, the jobstep command contains the subscriptionid, so it’s possible to look them up based on that. And of course, once the jobs have been found, they can be executed easily enough. In this example, I produce a list of the commands to run the jobs. I can copy the results out and execute them.
select 'exec sp_start_job @job_name = ''' + cast(j.name as varchar(40)) + ''''
from msdb.dbo.sysjobs j
join msdb.dbo.sysjobsteps js on js.job_id = j.job_id
join [ReportServer].[dbo].[Subscriptions] s on js.command like '%' + cast(s.subscriptionid as varchar(40)) + '%'
where s.LastStatus like 'Failure sending mail%';
Another option could be to return the job step commands directly (js.command in this query), but my preference is to run the job that contains the step.
© SQL Blog or respective owner