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.
Related
I'm trying to test setting up a data driven subscription that takes a parameter from the report but it wont validate the query, should I be able to do this.
SP: Select * from Table where Column = #Variable
The #Variable is called the same of the report.
This is 2017 version of reporting services
The subscription query does not allow parameters because it is meant to run on a schedule without interaction from a user.
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.
Is there a way to programmatically execute an existing subscription with different report parameters?
So far I execute subscriptions via SQL as follows:
EXEC ReportServer.dbo.AddEvent 'TimedSubscription', '<Subscriptions.SubscriptionID>'
But this seems to only allow me to execute the subscription as-is.
Edit:
I wanted to do this for our existing subscriptions (50+ total).
Manually re-creating each subscription is not feasible.
The first commenter in this article updates the Parameters value in the Subscriptions table via a Stored Procedure before running the AddEvent command:
update Subscriptions
set Parameters=
'<ParameterValues><ParameterValue><Name>Value</Name><Value>' + #value + '</Value></ParameterValue></ParameterValues>'
where SubscriptionID='XXX-XXX-XXX-XXX'
The way I worked through this problem was to set up a data driven subscription on the report that populated the parameters based on the values held within a specifically designed SQL table. I then set up a stored procedure that populated that table with the values that were required and then fired the subscription using AddEvent.
You may run into issues with this approach if you need to run fire the subscriptions more frequently than it takes to produce the report and thus cleaning out the lookup table. If the report isn't that frequent though, you should be fine.
If I'm understanding your question correctly, you could take 2 of the following approaches:
Approach 1
Step 1: Navigate to the report you would like run with different parameters.
Step 2: Select to manage the report
Step 3: Select to Create Linked Report
Step 4: Choose the location where the report can live.
Step 5: For the new linked report, click to manage the report
Step 6: Change the default parameters you'd like passed
Step 7: Create subscription for new linked report.
Approach 2
Step 1: Navigate to the report you would like run with different parameters.
Step 2: Select to manage the report.
Step 3: Create a subscription for the report
Step 3a: While creating subscription, specify what values you want passed.
Hope this helps!
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.
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.