Automatically set up user's subscription in SS

2019-05-14 12:45发布

问题:

I have a very simple report in SSRS that is just a table with three columns, an object name, client account, and expiration date.

In my report, I include a filter by UserID to limit the data to just the logged in user's client accounts.

I store the user's client accounts in a simple table with domain\alias | client account fields which is populated from a SSIS package.

When a new alias | client account association is entered, I would also like to set up a subscription to the report for this alias so they are notified when it is updated.

Is this possible?

I have recently discovered the Report Server Web Service and I'm thinking this may help. Am I able to set up new subscriptions here? Ideally I'd like to make a call to this in my SSIS package when a new client account is identified.

Also note, I don't believe data driven subscriptions will work for a couple reasons:
1) I am using the UserID parameter to filter the report
2) I would like users to be able to manage their subscription themselves once it is created under 'My Subscriptions'

UPDATE
I have been able to successfully create a subscription for myself using the web service (see below) and I am still looking into how this can be done for other users although it is not looking good:

ReportingService2010SoapClient service = new ReportingService2010SoapClient();
service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
TrustedUserHeader userHeader = new TrustedUserHeader();

string desc = "Send to Document Library";
string eventType = "TimedSubscription";
string scheduleXml =
       @"<ScheduleDefinition>" +
        "   <StartDateTime>2010-11-30T08:00:00-08:00" +
        "   </StartDateTime>" +
        "   <WeeklyRecurrence>" +
        "      <WeeksInterval>1</WeeksInterval>" +
        "      <DaysOfWeek>" +
        "         <Monday>True</Monday>" +
        "      </DaysOfWeek>" +
        "   </WeeklyRecurrence>" +
        "</ScheduleDefinition>";

ParameterValue[] extensionParams = new ParameterValue[4];

extensionParams[0] = new ParameterValue();
extensionParams[0].Name = "TO";
extensionParams[0].Value = "my alias";

extensionParams[1] = new ParameterValue();
extensionParams[1].Name = "IncludeReport";
extensionParams[1].Value = "FALSE";

extensionParams[2] = new ParameterValue();
extensionParams[2].Name = "IncludeLink";
extensionParams[2].Value = "TRUE";

extensionParams[3] = new ParameterValue();
extensionParams[3].Name = "Subject";
extensionParams[3].Value = "@ReportName was executed at @ExecutionTime";



string matchData = scheduleXml;
ExtensionSettings extSettings = new ExtensionSettings();
extSettings.ParameterValues = extensionParams;
extSettings.Extension = "Report Server Email";

string id;
service.CreateSubscription(userHeader, "/report path/report name",
                            extSettings, desc, eventType, matchData, null, out id );

I want to be able to do something like the following before calling CreateSubscription, but I can't do this without including the user's password.

NetworkCredential credentials = new NetworkCredential("alias", "", "userdomain");
service.ClientCredentials.Windows.ClientCredential = credentials;

or another option I found that doesn't require a password but throws a COM exception:

WindowsIdentity wi = new WindowsIdentity("alias@fqdn");
WindowsImpersonationContext ctx = null;
ctx = wi.Impersonate();

回答1:

re: I don't believe data driven subscriptions will work for a couple reasons:

1) I am using the UserID parameter to filter the report 2) I would like users to be able to manage their subscription themselves once it is created under 'My Subscriptions'

uh.. I'm pretty sure that data-driven-subscriptions WILL meet your needs, I think that I could work my way around both of those items in just a few minutes.

1) build a web-form to manage a table that drives the subscription. I mean, I could do this in dreamweaver in 10 minutes.

2) so pass the parameter, I guess I don't understand your hesitation



回答2:

Ended up using a custom solution that, for the time being, will require an admin to manage the user's subscriptions.