views:

875

answers:

1

I have a situation where I need my report server to be more-or-less publicly accessible, as we are using the ReportViewer control in an ASP.NET web application and groups of users will be accessing a variety of reports.

This will be running against SQL Server 2008 Standard Edition.

Security will be handled by creating linked reports (one for each user, published at run time when they request the report from our web app) but I'm having difficulty setting the linked report parameter values programmatically.

In a nutshell, a report has a small number of reserved parameter names (for example, UserID and LanguageID). At run time, the web app will check if the user has a linked report (using unique linked report names for each report/user) and create one if it does not exist.

This is being done using the SSRS SOAP API and is working great. The problem I'm having is in setting the report parameters for a linked report.

For example, if I log in as a sysadmin, I just want to see the report and have full reign over the parameters inside the report viewer. If I log in as a "low" user, I expect the UserID parameter to be set to my ID in the linked report, and not be able to change the UserID to snoop at other users' reports.

This can be accomplished manually in Report Manager by opening the linked report's properties and setting the parameter default values and unchecking the "Prompt User" box.

Now I'm trying to do that programmatically using the SOAP API and can't seem to find the correct way to do this.

I read hints in a few places that the CreateLinkedReport method can set parameters, but I'm beginning to think this is just a misunderstanding on the part of the authors. While this method does accept a Property[] properties, these properties only appear to provide report metadata (such as the linked report name).

Is there a special markup I need to use with the property name/values to indicate the property is a report parameter?

Any ideas are greatly appreciated.

A: 

Ah! Got it!

There are 2 SOAP methods: GetReportParameters and SetReportParameters

They are documented as working with reports, which are very much not linked reports, but this bit of functionality in the API appears to work with both.

For any future searchers: I've written a method to receive a ReportParameter[] (the result of GetReportParameters called on the linked report) and iterate through them. Pseudo/almostC# code:

ReportParameter[] reportParameters = ReportingService2005.GetReportParameters(LinkedReportName);
foreach( ReportParameter reportParameter in reportParameters)
{
   switch(reportParameter.Name)
   {
      case "ReservedParam1":
         reportParameter.DefaultValues = new string[1];
         reportParameter.DefaultValues[0] = CalculateReservedParam1();
         reportParameter.PromptUser = false;
      //etc
   }
}
try
{
   ReportingService2005.SetReportParameters(reportParameters);
}
catch (Exception e)
{
   // if error occurs while replacing params, delete linked report so user can't specify parameters they aren't entitled to
   ReportingService2005.DeleteItem(LinkedReportName);
   throw e;
}
Stefan Mohr