gpt4 book ai didi

sql-server-2008 - 从网页创建 SSRS 订阅

转载 作者:行者123 更新时间:2023-12-02 08:48:43 26 4
gpt4 key购买 nike

我在 SQL 2008 R2 上运行 Reporting Services,并创建了一些报表。我能够进入报表服务器并设置订阅,并将任何报表通过电子邮件发送到一个电子邮件地址。所以所有这些都配置正确。

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

我如何在 C# 中执行此操作?

最佳答案

您可以在 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);
}
}

关于sql-server-2008 - 从网页创建 SSRS 订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10335825/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com