Craig Porteous

SSRS Failed Subscription Alerting

February 10, 2017 by

Even now, with SQL Server 2016 SP1 released only a few months ago, it baffles me that there is still no built-in functionality to alert admins or users of failed subscriptions in Reporting Services. We still rely on scripts like the one I’m about to describe or report recipients contacting administrators/helpdesks when their report emails don’t arrive or fail to appear in file shares. This is something that people have had to work around for years. There is some documentation that Microsoft provides to help you get started with monitoring subscriptions from the log files with direction on using PowerShell but it is not by any means a complete solution. (Monitor Reporting Services Subscriptions)

Variations on a theme

As you can imagine, with this being a lingering issue in SSRS there have been a number of similar solutions and approaches to handle & troubleshoot failed subscriptions.

One such example is Dean Kalanquin’s blog post on MSDN from 2009 (Monitoring and Troubleshooting Subscriptions) which details how SSRS treats subscriptions with a few examples of why they’d fail. NOTE: Its only related to SQL Server 2005 & 2008 though.

Also there’s still many Active feedback posts with similar workarounds & no solutions. I.e. (Notification of SSRS subscription when it fails).

My Approach

With over 50 subscriptions set up by BI developers and over 100 created by users in a separate SharePoint integrated instance, there are a lot of potential failures that could be missed by both admins & users. This script was put together when we were running SQL Server 2008 & still remains in use through 2008 R2, 2014 & most likely when we upgrade to 2016 too. I have recently made my own improvements & tweaks as a pet project.

This is an example of the script’s output. I’ve kept it fairly simple as it’s used mainly by admins & to keep code maintenance to a minimum. As we are constructing it in HTML you can add any amount of formatting or customisation to suit your requirements.

The SQL script should be setup as a T-SQL step in a SQL Agent job, set to run as often as you require. The majority of my subscriptions go out at the same time each day so I have it running twice a day within a few hours of each other & only highlighting failures in the last 24 hours. This script will capture all SSRS based subscription failures:

  • Email subscriptions
  • File Share subscriptions
  • Data Driven subscriptions
  • Data source Cache refreshes

NOTE: The 24 hour restriction is good to stop you being spammed regularly by an unfixable error or one that requires further investigation. The downside being that on a rare occasion I’ve found a failure has been missed (on a monthly scheduled report) and only rediscovered months later when the user notified us of 2 months’ worth of reports missing. This is because the original failure would stop subsequent schedule runs from executing & the last run would be beyond the 24 hour window. To get the best of both worlds, you may be best running a “time restricted Agent job” daily and a non-restricted job once a month to capture any unresolved errors.

Upon discovering a failed subscription the script sends an email to the set recipients with all the relevant information, including the SQL Agent job name, (which is a horribly unreadable GUID for every SSRS subscription job). This allows you to re-run the subscription easily & clear the failure error.

Notes

I have excluded a few different status options in this script as they would be considered success scenarios. I may not have caught all possible options as this list was built over time. Feel free to change or adjust to suit. Microsoft provides a list of possible values for the Status column in the documentation I linked to at the start (Monitor Reporting Services Subscriptions) though it doesn’t cover Cache refreshes or subscriptions that may be executing when you query the table (ie. “Pending” status).

I have also defined a few specific variables which will need to be changed to suit your own environment.

This can be multiple users, simply separate them with a semicolon.

The profile will be the relevant Operator listed under the SQL Server Agent shown in Management Studio.

These are the only necessary changes you will need to make to the script for it to work. You can however, alter the fields returned, as well as the HTML section to include company logos or other formatting. In the case of several reporting instances, I further differentiate them by changing the colour of the header text in the email body by editing this HTML snippet:

N'<H3 style=”color:red; font-family:verdana”>

The main body of the email is created as an HTML table with the dataset placed inside & header’s manually defined. As you can see in the first SELECT statement I’ve added ISNULL to convert null values into zero length strings.

This is done as some subscriptions will have no value in the description field. The null causes the remaining columns in that row to move out of line. Its purely a formatting change.

Further Development

Although I’ve opted to keep the output simple, it is possible to add more functionality to the dataset, such as making report paths into clickable links to speed up troubleshooting. This can be achieved by wrapping a link tag with your report server URL around the [Path] field on the first select statement then casting as XML within the table select statement.

Eg.

‘<a href=“http://MyReportingSite.com/Reports/Pages/Report.aspx?ItemPath=’ + Cat.[Path] + ‘ “></a>’

It can be tricky if you are using special characters in report names or folders. This can break the XML conversion and cause the whole process to fail. Wrapping the field in a REPLACE would capture the most common character though

Failed Subscription Alerting T-SQL Script

This is a standardised version of the entire script that should be added as a T-SQL step to a SQL Agent job. I’ve commented out the date restriction that I mentioned above.

But PowerBI has it!

Much like we can now do (to a limited extent) with dataset refreshes in PowerBI (pictured) I would have expected Microsoft to have the functionality to alert on failed subscriptions in SSRS, especially as they are bringing the 2 products together with PowerBI On-prem. It may be something we need to wait much longer for though. Until then, I think this script fills that gap.

References


Craig Porteous
Reporting Services (SSRS)

About Craig Porteous

Craig is a Microsoft certified BI Developer & Administrator and has worked with the Microsoft SQL stack for over 8 years. From working with cloud technologies like AWS & PowerBI to managing enterprise level Projects & deployments, Craig is passionate about developing his skills. He enjoys contributing to a personal blog to give back to the SQL community. In his spare time Craig is an avid runner View all posts by Craig Porteous

168 Views