2

My code that sets up a ServerReport object on a web forms page, and then renders the report from SSRS to a pdf. Parameter and report name is passed by URL.

Private Sub Page_Load(sender As Object, e As EventArgs)

    Dim reportname As String
    'Dim parameter(0) As ReportParameter
    reportname = Request("reportname").ToString

    Dim v As New ReportViewer
    v.ProcessingMode = ProcessingMode.Remote
    Dim serverreport As New ServerReport
    serverreport = v.ServerReport
    serverreport.ReportServerUrl = New Uri("http://xxxxxx:80/ReportServer")
    serverreport.ReportPath = "/Reports/Aramid/Sheeter/" & reportname

    Select Case reportname

        Case Is = "NomexBlockCard" 'Or "NomexBlockLabel" Or "NomexInternalLabel"
            Dim paramList As New Generic.List(Of ReportParameter)
            paramList.Add(New ReportParameter("paramBlock", Request("paramBlock").ToString, False))
            serverreport.SetParameters(paramList)

        Case Is = "NomexRoutingData"
            Dim paramList As New Generic.List(Of ReportParameter)
            paramList.Add(New ReportParameter("paramWO", Request("paramWO").ToString, False))
            serverreport.SetParameters(paramList)

    End Select

    serverreport.ReportServerCredentials = New ReportViewerCredentials(user name here, password here, "CORE")
    Save(serverreport, "C:\WebReports\" & reportname & ".pdf")

    'now print
    Response.Redirect("reports.ashx?fileName=" & reportname)

End Sub


Public Sub Save(ByVal sr As ServerReport, ByVal savePath As String)
    Try
        Dim warnings As Warning() = Nothing
        Dim streamids As String() = Nothing
        Dim mimeType As String = Nothing
        Dim encoding As String = Nothing
        Dim extension As String = Nothing
        Dim deviceInfo As String
        Dim bytes As Byte()

        deviceInfo = "True" '<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>"
        bytes = sr.Render("PDF", Nothing, mimeType, _
        encoding, extension, streamids, warnings)
        Using Stream As New FileStream(savePath, FileMode.Create)
            Stream.Write(Bytes, 0, Bytes.Length)
            Stream.Close()
        End Using

    Catch ex As Exception


    End Try
End Sub

The report renders and saves as a pdf but the parameter value does not seem to be getting used in the report.

I have confirmed over and over that there is a value in paramBlock.

I don't know what I am doing wrong.

Am I missing a step or something?

Ryan

2
  • Perhaps the issue is in the report definition? I would add a textbox to the report and set it's Expression to the Parameter value. If the expected value appears, then your issue is in the report definition, not your code.
    – Mike Honey
    Nov 26, 2014 at 22:12
  • I added the text box and it looks good if I type the value of the parameter into a prompt on the report viewer, and the paramBlock in the ASP.NET code does have a value as confirmed by GetParameters. Running from the code gives me an error: "Parameter validation failed. It is not possible to provide valid values for all parameters"
    – Ryan
    Dec 2, 2014 at 15:59

5 Answers 5

5
+25

As your report is being rendered and saved, I'm assuming the credentials are set up correctly.

You can use the ServerReport.GetParameters function before saving the report to check what the parameters (and their values/properties) actually are.

Also, make sure you're setting every parameter required by the report (even those hidden or internal), and that every parameter value is within the allowed values of the parameter (if limits are set).

If the problem doesn't lie in passing the parameters, you might want to take a look at the report itself and how it handles its parameters.

6
  • Thanks Stan, the paramBlock in the ASP.NET code does have a value as confirmed by GetParameters. Running from the code gives me an error: "Parameter validation failed. It is not possible to provide valid values for all parameters"
    – Ryan
    Dec 2, 2014 at 16:01
  • You have your parameters hidden now (New ReportParameter("paramBlock", Request("paramBlock").ToString, False). Is this for a reason? Have you tried this without the False parameter?
    – Stijn
    Dec 2, 2014 at 16:09
  • Per a suggestion I modified my parameter code to: Dim paramList As New Generic.List(Of ReportParameter) paramList.Add(New ReportParameter("paramBlock", Request("paramBlock").ToString)) I still get the parameter validation error even with the False parameter taken out serverreport.SetParameters(paramList)
    – Ryan
    Dec 2, 2014 at 16:14
  • There are some possible solutions here.
    – Stijn
    Dec 2, 2014 at 16:21
  • Also, make sure you're setting every parameter required by the report. And that every parameter value is within the allowed values of the parameter (if limits are set).
    – Stijn
    Dec 2, 2014 at 16:26
3

From your recent comment about a "Parameter validation failed" error, it sounds like your issue is not with your calling code structure, but rather matching the parameters to the report definition.

The most common issue is hidden or internal parameters which you are ignoring. You need to carefully review the parameter design in SSRS Report Designer, and make sure your passed parameters comply with what it expects.

2

Consider following suggestions. It might help you to resolve your issue. After considering every point, you can try your code

  1. Place following code just above the Select Case reportname statement line serverreport.ReportServerCredentials = New ReportViewerCredentials(user name here, password here, "CORE")

  2. You can also try changing code line serverreport.ReportServerCredentials = New ReportViewerCredentials(user name here, password here, "CORE")

To

ServerReport.ReportServerCredentials.NetworkCredentials = System.Net.CredentialCache.DefaultCredentials

  1. If your report has default parameters, then remove default parameters and test your code And also remove exception handling from your method Public Sub Save(ByVal sr As ServerReport, ByVal savePath As String)
2

You can try following code:

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim reportname As String = Request("reportname").ToString 'Dim parameter(0) As ReportParameter

    Dim v As New ReportViewer
    v.ProcessingMode = ProcessingMode.Remote
    Dim ServerReport As ServerReport
    ServerReport = v.ServerReport
    serverreport.ReportServerUrl = New Uri("http://xxxxxx:80/ReportServer")
    serverreport.ReportPath = "/Reports/Aramid/Sheeter/" & reportname

    ServerReport.ReportServerCredentials.NetworkCredentials = System.Net.CredentialCache.DefaultCredentials

    Select Case reportname

        Case Is = "NomexBlockCard" 'Or "NomexBlockLabel" Or "NomexInternalLabel"
            Dim paramList As New Generic.List(Of ReportParameter)
            paramList.Add(New ReportParameter("paramBlock", Request("paramBlock").ToString, False))
            serverreport.SetParameters(paramList)

        Case Is = "NomexRoutingData"
            Dim paramList As New Generic.List(Of ReportParameter)
            paramList.Add(New ReportParameter("paramWO", Request("paramWO").ToString, False))
            serverreport.SetParameters(paramList)

    End Select


    Save(serverreport, "C:\WebReports\" & reportname & ".pdf")



End Sub


Public Sub Save(ByRef sr As ServerReport, ByVal savePath As String)
    Try
        Dim warnings As Warning() = Nothing
        Dim streamids As String() = Nothing
        Dim mimeType As String = Nothing
        Dim encoding As String = Nothing
        Dim extension As String = Nothing
        Dim deviceInfo As String
        Dim bytes As Byte()

        deviceInfo = "True" '<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>"

        bytes = sr.Render("PDF", Nothing, mimeType, _
        encoding, extension, streamids, warnings)
        Using Stream As New FileStream(savePath, FileMode.Create)
            Stream.Write(bytes, 0, bytes.Length)
            Stream.Close()
        End Using

    Catch ex As Exception


    End Try
End Sub
2

Maybe this is not the case, but I remember that Parameters value can be lost during PostBack.

So I would try a syntax like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not Me.Page.IsPostBack Then
        'your code to setup and print report
    End If

End Sub

If this solution doesn't work please provide the code used in Report Definition.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.