SSRS Subscription: Send Email on Report Failure - reporting-services

I have an SSRS report with some pre-selected parameters.
Every once in a while, a report parameter will randomly blank itself out and the subscription won't create the file.
Is there a way I can be emailed in the event that the server can't create the report?

I faced a similar problem, I ended up by creating configuring the Database Mail and creating an Operator to notifies me when the underlying job of the subscription fails.
Configure Database Mail to send a mail through a SMTP server even gmail or outlook works.
Create an Operator, Operators are aliases for people or groups that can receive electronic notification when jobs have completed or alerts have been raised.
Identify the underlying job that runs your subscription, use this query against the ReportServer database.
SELECT
c.Name AS ReportName
, rs.ScheduleID AS JOB_NAME
FROM
dbo.Catalog c
JOIN dbo.Subscriptions s ON c.ItemID = s.Report_OID
JOIN dbo.ReportSchedule rs ON c.ItemID = rs.ReportID
AND rs.SubscriptionID = s.SubscriptionID
The JOB_NAME column will give you the name of the job.
SQL Server Agent via SSMS go to the Jobs folder look for the job and right click it to go to properties.
In the Notifications tab set the Operator created before and the condition to send the mail.

Related

Execute Report Data-driven Subscription with T-SQL

I'm trying to use the SQL agent job created by an SSRS data-driven subscription to generate a report. Another application uses a stored procedure to insert data. I would like to generate a report immediately after the data is inserted by modifying that stored procedure to execute the SQL Server Agent. My code is follows:
USE msdb EXEC sp_start_job #job_name = 'F2B1...'
This approach works perfectly when the Agent job is from a standard subscription. With a Data-driven description, the value of the LastStatus column is "pending" for a long while and then changes to "Done: 1 processed of 1 total; 1 errors". I do not see an error in the SQL Agent error log.
Is there a way to do something like this? If so, can I pass the parameters to the report or does it still execute the query defined in the data driven subscription?
Thanks!
You can also kick off a subscription by Subscription ID.
EXEC dbo.AddEvent #EventType = 'TimedSubscription', #EventData = '<YOUR SUBSCRIPTION ID HERE>'
Where the Event Data parameter is the Subscription ID of your report's subscription.
I actually haven't tried this with a Data Driven Subscription before though.

SSRS email subscription event trigger - Data values changed (not Timed subscription)

I want an SSRS report to send a report subscription (email or file share) based on a Data Value change in the report data set.
Let’s say 500 rows of the Newest Data in a table all have "Update Time= 9/19 1:40 pm” and then 50 minutes later that table is updated to insert 200 new rows with "Update Time=9/19 2:30pm”. The data value change in this example is the ‘Update Time’ has changed on all records. I want SSRS to be triggered at 2:30pm based on in this change in the dataset records, and then SSRS will email the new 200 records.
Can SSRS do this kind of delivery? Is “data-driven” the answer? (Doesn’t look to me like data-driven solves this problem; but perhaps I am just not understanding?). Does snapshot update achieve this? (I thought snapshots are also time driven?).
SQL Version:
Microsoft SQL Server 2016 (SP2-CU2) (KB4340355) - 13.0.5153.0 (X64)
Jun 28 2018 17:24:28
Copyright (c) Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2012 R2 Datacenter 6.3 <X64> (Build 9600: ) (Hypervisor)
NOTE: I will use RANK() windowing function to achieve that grouping pretty easily-- It would group everything as 1 (200) rows, 2 (500) rows, etc. I would keep only group 1, so all of the records would have a new ‘Update Time’.
https://learn.microsoft.com/en-us/sql/reporting-services/subscriptions/subscriptions-and-delivery-reporting-services?view=sql-server-2017#triggering-subscription-processing.
Triggering subscription processing
The report server uses two kinds of events to trigger subscription
processing: a time-driven event that is specified in a schedule or a
snapshot update event.
A time-driven trigger uses a report-specific schedule or a shared
schedule to specify when a subscription runs. For on-demand and cached
reports, schedules are the only trigger option.
A snapshot update event uses the scheduled update of a report snapshot
to trigger a subscription. You can define a subscription that is
triggered whenever the report is updated with new data, based on
report execution properties that are set on the report.
Processing a data-driven subscription
Data-driven subscriptions can produce many report instances that are
delivered to multiple destinations. The report layout does not vary,
but the data in a report can vary if parameter values are passed in
from a subscriber result set. Delivery options that affect how the
report is rendered and whether the report is attached or linked to the
e-mail can also vary from subscriber to subscriber when the values are
passed in from the row set.
Data-driven subscriptions can produce a large number of deliveries.
The report server creates a delivery for each row in the row set that
is returned from the subscription query.
As far as I can see, you are correct. The snapshot update method would require snapshots to be created and snapshots are only created on a schedule or manually by a user.
What might have less overhead than a datadriven subscription is to have a stored procedure that runs the simplest query to detect if any pertinent data has changed and, if so, trigger the subscription.
EXEC dbo.AddEvent #EventType = 'TimedSubscription', #EventData = '00f4ecee-891d-445f-ae81-24ef62d3fb53'
Where the Event Data is your subscription ID (copy the Edit subscription link to get the ID)
Of course you'd have to run an SSIS job to execute your stored procedure every 15 min or so but I think it's better than the data driven subscription.

Find where report email job is

I'm having a report (.rdl) in Visual Studio 2012. I know that this report is sent by email every day at 5AM, but I can't find the job that is doing this. I've been looking in SQL Server Agent jobs but it's not there.
I've heard the job can't be in SQL Server agent because then the pictures in the report can't be attached to the email (don't know if that's true?).
I have tried looking in Reporting Services Configuration Manager by connecting to the db, but I think it's only the service/server(?) properties there. Couldn't find any email job sending that report.
When I look at the dataset that is used for the report I can only find the source that fills it (a stored procedure), but that doesn't help me much..
Do you know where else to look to find this job? What is normal when trying to send a .rdl report email? Is it possible to do this from VS 2012?
Report Subscriptions are run through SQL Server Agent.
You can get the job names, which are GUID type strings, with a query like this against your ReportServer database:
select JobName = rs.ScheduleID
, ReportName = c.Name
from ReportSchedule rs
inner join [Catalog] c on rs.ReportID = c.ItemID
Which will give a result like:
This matched jobs that can be seen in the SQL Server Agent:
You can check the job and see what it's doing:
i.e. calling a stored procedure on the ReportServer database.
See SSRS Subscriptions and their SQL Server Agent job names for a more detailed query.

what runs the subscribed report in SSRS?

so my question is, what runs the subscribed report in SSRS ? I mean when I subscribe to report and give it a desired time when it should run and send me the file. something does this right ? so I want to know what runs it ? is it a procedure in SQL function ? well the reason why I want to know this is that I want to run SQL update before each time this scheduled report starts.
I can just create procedure that will do the update I want before the scheduled time but, still it will be more practical to integrate it within the job itself
Short answer, these subscriptions are run as database jobs through the SQL Server Agent.
They are created with GUID type names:
The one job step will have a command like:
exec [ReportServer].dbo.AddEvent #EventType='SharedSchedule', #EventData='8df4ff30-97d3-41f7-b3ef-9ce48bfdfbfa'
You can trace these jobs/GUIDs back to the subscription and report through the ReportServer database using the Subscriptions table and its MatchData column (matches the job GUID) and the Catalog table which includes the report data (i.e. linked through the Subscriptions.Report_OID column.
You can use this information to check what's scheduled and based on this schedule your update appropriately.
I haven't tried it myself, but one option could even be to hook into the existing database jobs, but I would approach this with caution; I can't see any issues but maybe it's best not to update any system created jobs like these.

SSRS - How can I conditionally send a report to a mail address

Let me specify the environment. The client has UI for entering orders in SQL Server database. A Windows Service one another machine is processing these orders from database at particular intervals. Sometimes the Windows service is stopped then orders piles up. To avoid that I have created a SQL Server Report which is run at an interval of 5mins. It checks how many orders are processed and creates a status report. What I want, if count of processed order is zero then the report be mailed to system administrator. Then he will check the machine where the service is hosted and restart the service, so that all rework is avoided. So the question is how to implement this conditional delivery of report. In short, if count is zero no report be mailed otherwise it must.
This is 4 years late, but for anyone who stumbles onto this, a Data Driven Subscription will do the trick.
In short, you can create a query that returns the recipients if there is data, or NULL if there isn't any data.
This can be done by using Data Driven Subscription, where we have to put some SQL condition query in which it return ToEmail Address if data is present then ToEmail Address will not be blank or NULL
Below are some code that will help
IF EXISTS(SELECT 1 from Table where datefield = CONVERT(varchar(13),GETDATE() -1 ,23)+' 00:00:00.000' )
Select ToEmailAddress ='abc.pqr#xyz.com'
ELSE
Select ToEmailAddress =''
It's a common problem with SSRS 2005 (not sure about 2008) - there's no easy way to stop an empty report from being sent.
Link
The solution I had to use (and yes, I know it's ugly, inefficient, and somewhat embarrassing...), is to run your search query in a stored procedure. If rows are not found, cause an error. If rows are found, re-run your query.
SELECT * FROM TABLE
IF ##RowCount = 0
BEGIN
SELECT 1/0
ELSE
SELECT * FROM TABLE
END
Returning an error will prevent the subscription from emailing the report.