从网页创建SSRS订阅

时间:2012-04-26 14:45:55

标签: sql-server-2008 reporting-services ssrs-2008

我在SQL 2008 R2上运行Reporting Services并且有一些我创建的报告。我可以进入Report Server并设置订阅,并将任何报告通过电子邮件发送到电子邮件地址。所以这一切都配置正确。

我想要做的是在我的应用程序中有一个显示可用报告列表的网页。用户可以选择一个,选择计划频率,输入电子邮件地址,然后单击“保存”按钮。单击“保存”时,应在SSRS中创建订阅。我可能需要根据报告传递几个报告参数。

我怎样才能在C#中做到这一点?

2 个答案:

答案 0 :(得分:5)

您可以在SSRS中为报告动态生成一次性订阅。你必须使用Diego提到的RS网络服务。

您的代码看起来像这样:

static void generateSubscription()
{
    if (SubscriptionRequests.Count < 1) return;

    NetworkCredential credentials = new NetworkCredential("user", "pass");
    reports.ReportingService2005 rs = new reports.ReportingService2005();
    rs.Credentials = credentials;
    DateTime topDatetime = DateTime.Now;
    topDatetime = topDatetime.AddMinutes(2);

    foreach (SubscriptionRequest x in SubscriptionRequests)
    {
        reports.ExtensionSettings extensionSettings = new reports.ExtensionSettings();
        List<reports.ParameterValue> extParameters = new List<reports.ParameterValue>();
        List<reports.ParameterValue> parameters = new List<reports.ParameterValue>();
        string description = "Email: ";
        string eventType = "TimedSubscription";
        extensionSettings.Extension = "Report Server Email";

        string scheduleXml = "<ScheduleDefinition><StartDateTime>";
        scheduleXml += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
        scheduleXml += "</StartDateTime></ScheduleDefinition>";

        parameters.Add(new reports.ParameterValue() { Name = "abc", Value = x.id });


        extParameters.Add(new reports.ParameterValue() { Name = "RenderFormat", Value = x.renderFormat });
        extParameters.Add(new reports.ParameterValue() { Name = "TO", Value = x.email });
        extParameters.Add(new reports.ParameterValue() { Name = "ReplyTo", Value = x.replyTo });
        extParameters.Add(new reports.ParameterValue() { Name = "IncludeReport", Value = "True" });
        extParameters.Add(new reports.ParameterValue() { Name = "Subject", Value = "subject - " + " (" + x.id.ToString() + ")" });

        extParameters.Add(new reports.ParameterValue() { Name = "Comment", Value = x.body });
        extensionSettings.ParameterValues = extParameters.ToArray();

        description += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
        description += " (" + x.a + " - " + x.b + " - " + x.c + ")";
        string _reportName = "/report";
        rs.CreateSubscription(_reportName, extensionSettings, description, eventType, scheduleXml, parameters.ToArray());
        topDatetime = topDatetime.AddSeconds(30);
    }           
}  

答案 1 :(得分:1)

最简单的方法是在“浏览器”预定义角色下为用户提供对报表管理器的访问权限。这正是此角色的用途,查看文件夹和报告以及订阅报告。

如果不可能,您可以创建自己的管理工具。为此,您需要访问SSRS Web方法使用SOAP和ReportService2005端点

示例here