views:

2164

answers:

1

I have an SSRS report that is displayed to users in the ASP.NET ReportViewer control. The report has many parameters and we're using the parameter prompts that the ReportViewer control offers. Depending on a certain parameter of the report, we only need to have the user prompted for a subset of the rest of the report parameters.

We could have used linked reports and hide the appropriate parameters, but there are many possible combinations to that first parameter (it's multi-valued), so we'd rather not do that. Instead, we have an ASP.NET ListBox that controls the first parameter and when it's selection is changed, we are using the ReportViewer.ServerReport.SetParameters() function to hide/show parameters (it takes in an array of ReportParameter and the ReportParameter constructor takes in a boolean to hide/show the parameter).

Here's the issue. Everything works fine in our development environment. When we deploy the report and the ASP.NET site to the production environment, parameters never get shown when those SetParameters() calls are invoked. We know the code is called because we put some debugging output to make sure. The code to hide parameters is working fine. It's just the code that should cause certain parameters to show up again doesn't work. Not only does it not show up the parameter prompts, but the Visible property of the parameter does not get set to true (checked by using ReportViewer.ServerReport.GetParameters()).

We have SQL Server 2005 SP3 installed in both environments, and the same version of the report viewer control (Microsoft.ReportViewer.WebForms.dll). Any ideas what could be wrong? Any workaround ideas? If you have questions, leave comments.

Edit: After further investigation, we isolated the problem further. I made a simple report with just 1 parameter without any DB connection. Then I made an aspx page with 2 buttons and a ReportViewer control hooked up to that report. 1 button hides the parameter and 1 button shows the parameter (using the SetParameters() function, as mentioned above). Even with this simple scenario, the hide/show buttons work fine in the development environment, but we still have the same issue in the production environment (the show button doesn't work). We also tried this on another server on the network in the production environment, and we have the same issue. So everything seems to work fine in the development environment, but on 2 different servers outside that environment we seem to be getting the same issue.

Edit2: Below is the code behind for the test report page. The page has a ReportViewer, 2 Buttons, and a Label for debug output. When the showing of hidden parameters doesn't work, the Label even shows that the Visible property is still false after the call to ShowParameter.

Public Partial Class TestReportPage
    Inherits System.Web.UI.Page

    Public Sub HideParameter(ByVal parameterName As String)
        Dim parameters As ReportParameterInfoCollection = ReportViewer1.ServerReport.GetParameters()
        ReportViewer1.ServerReport.SetParameters(New ReportParameter() {New ReportParameter(parameterName, GetParameterDefaults(parameterName, parameters), False)})
        parameters = ReportViewer1.ServerReport.GetParameters()
        lblTest.Text &= "Hide param " & parameterName & "; Is Visible: " & parameters(parameterName).Visible & "<br>"
    End Sub
    Public Sub ShowParameter(ByVal parameterName As String)
        Dim parameters As ReportParameterInfoCollection = ReportViewer1.ServerReport.GetParameters()
        ReportViewer1.ServerReport.SetParameters(New ReportParameter() {New ReportParameter(parameterName, GetParameterDefaults(parameterName, parameters), True)})
        parameters = ReportViewer1.ServerReport.GetParameters()
        lblTest.Text &= "Show param " & parameterName & "; Is Visible: " & parameters(parameterName).Visible & "<br>"
    End Sub
    Public Shared Function GetParameterDefaults(ByVal parameterName As String, ByVal parameters As Microsoft.Reporting.WebForms.ReportParameterInfoCollection) As String()
        Dim paramDefaults() As String = {}
        Dim i As Int16 = 0
        For Each paramValue As String In parameters(parameterName).Values
            ReDim Preserve paramDefaults(i)
            paramDefaults(i) = paramValue
            i = i + 1
        Next
        Return paramDefaults
    End Function
    Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        HideParameter("foo")
    End Sub
    Protected Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ShowParameter("foo")
    End Sub
End Class
A: 

Just for anyone else who ever has this issue, here's the reason we were having this issue:

The issue was due to a difference in the environments. Even though we had the ReportViewer DLL being copied into the bin folder of the project (and thus copied to where the project was hosted), this issue w/the params is a bug in older versions of the ReportViewer control. You need to get the Microsoft Report Viewer Redistributable 2005 SP1 to fix this issue. Apparently we had this fix installed in the development environment. For some reason the ReportViewer DLL was the same version on both sides though. This could be because the DLL was actually being accessed from a different location.

Liron Yahdav