http://www.mssqltips.com/sqlservertip/3078/report-launcher-to-run-ssrs-report-subscriptions-on-demand/?utm_source=dailynewsletter&utm_medium=email&utm_content=headline&utm_campaign=20131024

Problem

SSRS report subscriptions are a great feature for automatic report delivery on regular schedule. Unfortunately, there is no easy way to run  a subscribed report on demand. If you need to run one of these reports on  demand, you will need to dig into the Report Server database to find the right subscription. When it is needed  to be run on demand more frequently, it becomes annoying and you lose valuable time.

Solution

This tip will show how this can be handled more elegantly by two new SSRS reports. One report will allow us to run individual subscriptions of reports and the second will allow to run all subscriptions handled by a schedule.

Background

The automatic execution of report subscriptions is handled by SQL Server Agent. SSRS  creates a separate agent job for each shared schedule and each individual  schedule. The jobs are named by the GUIDs of that particular schedules as shown  below which are not very useful.

If you take a closer look at the job created by SSRS you will notice that in fact the job does not executes the report itself, but instead it calls  the [dbo].[AddEvent] stored procedure from the report server database to add an event into  the [dbo].[Event] table.  Based on the subscription schedule there are 2 types of events - TimedSubscription or SharedSchedule.

exec [ReportServer].dbo.AddEvent
@EventType='TimedSubscription',
@EventData='be13bfa4-9c36-423f-90b8-bd449bfd7eb3'
exec [ReportServer].dbo.AddEvent
@EventType='SharedSchedule',
@EventData='3045b1a3-ce3b-430e-a5dd-99953d389d80'

The @EventType parameter of the [dbo].[AddEvent] stored procedure specifies a type of Schedule and the @EventData represents  the GUID for the particular shared schedule or GUID of an individual subscription.

SSRS regularly checks the events in the reports server database and if it finds one of the above mentioned events, it automatically starts processing the subscriptions. In  the case of a TimedSubscription the single subscription is processed and in the case of  a SharedSchedule all subscription sharing that schedule are processed one by one.

Creating SSRS Reports to Launch Reports

We will design the reports so each of the reports will have three datasets.  The first dataset will get information about the Subscriptions or Schedules. The second dataset will handle execution of the subscription or schedule and the third dataset will provide information about  the launched subscription or schedule and that information will be shown on the report itself.

Our reports will use four different tables from the Report Server database.

  • [dbo].[Catalog] - catalog table which contains information about all reports and folders in the SSRS Instance
  • [dbo].[Subscriptions] - table containing information about all subscriptions
  • [dbo].[Schedule] - containing information about all schedules
  • [dbo].[ReportSchedule] - contains links among Schedules, Subscriptions and Reports

SSRS report to launch individual subscription reports

The first report to develop will handle launching individual subscriptions

The report contains two parameters SubscriptionToLaunch and LaunchedSubscritption. Available values of the SubscriptionToLaunch is populated by the ReportSubscriptions Dataset and is used to select  a particular subscription for execution. The LaunchedSubscription has a default value populated by the LaunchSubscription Dataset, which handles the execution itself and is subsequently used by the LaunchedSubscriptionDetails Dataset, which returns details for the launched subscription and information from this data set are shown on the report itself.

ReportSubscriptions Dataset

As mentioned above, the ReportSubscriptions dataset is used to populate the SubscriptionsToLaunch parameter and  the purpose of this parameter is to select a particular subscription for execution.  This queries the [dbo].[Subscriptions] and [dbo].[Catalog] tables. From the subscription we will receive the [SubscriptionID] and subscription [Description] and from the [dbo].[Catalog] we retrieve  the subscribed report [Name].

SELECT
S.[SubscriptionID]
,C.[Name] + ' (' + S.[Description] + ')' AS [DisplayName]
FROM [dbo].[Subscriptions] S
INNER JOIN [dbo].[Catalog] C ON S.[Report_OID] = C.[ItemID]
ORDER BY [DisplayName]

LaunchSubscription Dataset

This dataset handles the execution of the subscription by calling the [dbo].[AddEvent] stored procedure in ReportServer database. Because the [dbo].[AddEvent] stored procedure does not return any record set, we have to return some information so the Dataset can be used by reporting services. Because of this,  the query contains a SELECT statement, which returns the SubscriptionID. The @EventData variable is mapped to the SubscriptionToLaunch parameter.

exec [dbo].[AddEvent] 'TimedSubscription', @EventData;
SELECT
@EventData AS [SubscriptionID]

LaunchedSubscriptionDetails DataSet

The third dataset provides information about launched subscriptions. Data from this dataset are used on the report to inform users about subscription and report details.

SELECT
S.[Description] AS [SubscriptionDescription]
,C.[Name] AS [ReportName]
,S.[DeliveryExtension]
FROM [dbo].[Subscriptions] S
INNER JOIN [dbo].[Catalog] C ON S.[Report_OID] = C.[ItemID]
WHERE
S.[SubscriptionID] = @LaunchedSubscription

Once you compose everything together, you can use the report for launching subscriptions. The final result will look like below.

SSRS report to launch shared scheduled reports

The second report mentioned is used to execute shared schedules. When a shared schedule is launched, all the subscriptions using that shared schedule will be launched one by one. The structure of the report is the same as the previous  report with only slight differences in the queries.

ReportSchedules Dataset

In contrast to the ReportSubscriptions query for the previous report, we will query only the names of  the shared schedules. We get this information from the [dbo].[Schedules] table. As this table contains records for both SharedSchedules and also for TimedSubscriptions, we limit the results only to  get the shared ones. Also we get only schedules for which a record in [dbo].[ReportSchedule] exists as we do not want to execute shared schedules without a report subscription.

SELECT
[ScheduleID],
[Name]
FROM [dbo].[Schedule] S
WHERE
[EventType] = 'SharedSchedule'
AND
[ScheduleID] IN (SELECT [ScheduleID] FROM [dbo].[ReportSchedule])
ORDER BY [Name]

LaunchSchedule Dataset

The LaunchSchedule is similar to the LaunchSubscription query. The only difference is that instead of passing TimedSubscription as @EventType we will pass SharedShedule.

exec [dbo].[AddEvent] 'SharedSchedule', @EventData;
SELECT
@EventData AS [ScheduleID]

LaunchedScheduleDetails Dataset

Again similar to the LaunchedSubscriptionDetails dataset from the previous report, this will return details about the executed schedule. In contrast to the LaunchedSubscriptionDetails, this query can return multiple rows as one shared schedule can handle multiple report subscriptions.

SELECT
S.[Description] AS [SubscriptionDescription]
,C.[Name] AS [ReportName]
,S.[DeliveryExtension]
FROM [dbo].[ReportSchedule] RS
INNER JOIN [dbo].[Subscriptions] S ON RS.[SubscriptionID] = S.[SubscriptionID]
INNER JOIN [dbo].[Catalog] C ON RS.[ReportID] = C.[ItemID]
WHERE
RS.[ScheduleID] = @LaunchedSchedule

Once the report is composed, we can use it to launch subscriptions handled by shared schedules. The result will look like the image below.

Next Steps
  • Reports presented in this tip provide only basic information. You can elaborate on the reporting database and update the reports to provide more information about the subscriptions and reports.
  • Reports as they are presented here are suitable for administrators. You can create a set of stored procedures in the reporting database to get the subscriptions and schedules and also create procedures for launching subscriptions and returning necessary information. These procedures can process information about  the currently logged in user and limit the execution to subscriptions and schedules created by the user who is running the report. Then you can provide such reports to end users to allow them on demand execution of subscriptions.
  • You can create additional overview reports for the Schedules and Subscription which will allow you to group and sort the subscriptions. Then upon a click you can execute these reports providing  the right parameters to launch a particular subscription.
  • You can download the complete SSRS project with sample reports here.

Report launcher to run SSRS report subscriptions on demand的更多相关文章

  1. Session for SSRS Report of Microsoft Dynamics AX

    Session for SSRS Report of Microsoft Dynamics AX 版权声明:本文为博主原创文章,未经博主允许不得转载. Contract •A data contrac ...

  2. Dynamics CRM 2015中的SSRS Report集成配置

    大家应该都知道.Dynamics CRM能集成SSRS Report,而且我也在之前的博文中讨论过怎样制作一个简单的SSRS Report并部署到Dynamics CRM中.今天我们来看看一些比較有用 ...

  3. Dynamics AX 2012 R2 从代码中调用SSRS Report

    平时,我们制作SSRS Report的方法主要有两种:使用Query或RDP.如果需要为报表传递参数,就要在代码中为报表参数赋值,然后在代码中调用报表.下面我总结下这两种报表在代码中传参和调用的方式: ...

  4. How to get the underlying SSRS Report Query, reset query , add your own ranges and execute report [AX2012]

    Below is the small code snippet to get the underlying query of the SSRS report, reset query, prompt ...

  5. SSRS Report Knowledge Base

    1. 获取Textbox的值,根据Textbox值更改单元格颜色 Textbox值:=ReportItems!Textbox1.Value 当前单元格的值:=Me.Value =IIF(ReportI ...

  6. 解决:insert Vodafone sim card,open the mms read report,when receive the read report,cann't download..

    insert Vodafone sim card,open the mms read report,when receive the read report,cann't download the m ...

  7. 解决:insert Vodafone sim card,open the mms read report,when receive the read report,cann't download..

    insert Vodafone sim card,open the mms read report,when receive the read report,cann't download the m ...

  8. How to display SSRS report based on customer/Vendor specific language [AX2012]

    Common requirement is to show the reports in customer’s language. [example : Quotations, sales confi ...

  9. How to using expression setup BackgroundColor AX2012 SSRS Report[AX2012]

    tile label using [#99ccff] property BackgroundColor - > expression =Iif(Fields!Flag.Value = " ...

随机推荐

  1. How to control printer orientation(Landscape / Portrait) for an AX report in X++

    You should try this: 1. Set property Orientation on your report design to Auto 2. In your fetch meth ...

  2. SQL Server 2008 R2【SET ANSI_PADDING填充属性】插入一条数据后,为何每一列都默认的在字符后多了几个空格

    当加入空格后查出 解决: 导致出现这样的现象的原因就是SET ANSI_PADDING选项. 这个选项只在数据表的字符串字段被更新或者新的数据行插入到表中的时候作用.它控制着SQL Server在遇到 ...

  3. std::map的clear()没有用?

    昨天晚上,我徒弟跑过来讲,他的程序的内存占用居高不下,愿意是std::map的clear()没有效果.于是我让他用erase(begin,end); 试试也不行. 代码如下: void release ...

  4. 用Intellij IDEA 创建第一个maven项目!

    1. 一直想如何复用以前项目的maven的jar包! 其实只要拿到pom.xml即可!!! 1.1 创建一个maven项目 2. 3. 创建项目名和项目路径,我给项目起的名字是mavenV1.0 4. ...

  5. JavaScript:实现瀑布流

    一.前言: 瀑布流现在是一个非常常用的布局方式了,尤其在购物平台上,例如蘑菇街,淘宝等等. 二.流程: 1.在html文件中写出布局的元素内容: 2.在css文件中整体对每一个必要的元素进行样式和浮动 ...

  6. Java基础——数组应用之StringBuilder类和StringBuffer类

    接上文:Java基础——数组应用之字符串String类 一.StringBuffer类 StringBuffer类和String一样,也用来代表字符串,只是由于StringBuffer的内部实现方式和 ...

  7. 第八篇 SQL Server代理使用外部程序

    本篇文章是SQL Server代理系列的第八篇,详细内容请参考原文 在这一系列的上一篇,学习了如何用SQL Server代理作业活动监视器监控作业活动和查看作业历史记录.在实时监控和管理SQL Ser ...

  8. curl命令常见用法汇总 good

    curl是一种命令行工具,作用是发出网络请求,然后得到和提取数据,显示在"标准输出"(stdout)上面. curl是一个强大的命令行工具,它可以通过网络将信息传递给服务器或者从服 ...

  9. c# 多线程与异步调用

    异步操作的本质 在方法调用前为异步方法指定一个回调函数,方法调用后被线程池中的一个线程接管,执行该方法.主线程立即返回,继续执行其他工作或响应用户请求.如果异步方法执行完 毕,回调函数被自动执行,以处 ...

  10. Eclipse 文本显示行号