views:

116

answers:

3

I'm trying to fix an issue with an application I'm supporting (I didn't write the code). The code takes an SSRS report and renders it in pdf format. Users are sporadically getting the error indicated in the title. There is no rhyme or reason to when the error is generated (a particular report will run one time and throw the error the next). The code is below.

  Public Sub OpenReport()
        Dim MyParms As New Generic.List(Of ReportParameter)
        Dim mimeType As String = Nothing
        Dim encoding As String = Nothing
        Dim extension As String = Nothing
        Dim deviceInfo As String = Nothing
        Dim streamids() As String = Nothing
        Dim warnings As Microsoft.Reporting.WebForms.Warning() = Nothing
        Dim bytes() As Byte 
        Dim format As String = "PDF" ''#to open the report in pdf; report viewer invisible

        Try
            If dropReports.SelectedItem.Value = "1" Then

                If Session("IsBDAP") = True Then
                    MyParms.Add(New ReportParameter("SCAId", dropSCA.SelectedItem.Value, False))
                Else
                    MyParms.Add(New ReportParameter("SCAId", Server.UrlEncode(Session("SCAId")), False))
                End If
                MyParms.Add(New ReportParameter("ProviderId", dropProvider.SelectedItem.Value, False))
                If dropVisit.Visible = True Then
                    MyParms.Add(New ReportParameter("VisitId", dropVisit.SelectedItem.Value, False))
                End If
                MyParms.Add(New ReportParameter("FY", dropContractFY.SelectedItem.Value, False))

                ReportViewer1.ProcessingMode = ProcessingMode.Remote
                ReportViewer1.ServerReport.ReportServerUrl = New Uri(System.Configuration.ConfigurationManager.AppSettings("ReportServerURI"))
                ReportViewer1.ServerReport.ReportPath = Session("ReportsFolder") & "MReport"
                ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
                ReportViewer1.ServerReport.SetParameters(MyParms)
                ''#Code to convert the report to pdf 
                deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>"
                bytes = ReportViewer1.ServerReport.Render(format, deviceInfo, mimeType, encoding, extension, streamids, warnings)
                Dim size As Integer = bytes.Length
                ReportViewer1.ServerReport.Refresh()
                Response.Buffer = True
                Response.Clear()
                Response.ContentType = mimeType
                Response.AddHeader("content-disposition", "attachment; filename=MReport." + extension)
                Response.BinaryWrite(bytes)


            ElseIf dropReports.SelectedItem.Value = "2" Then

                If Session("IsBDAP") = True Then
                    MyParms.Add(New ReportParameter("SCAId", dropSCA.SelectedItem.Value, False))
                Else
                    MyParms.Add(New ReportParameter("SCAId", Server.UrlEncode(Session("SCAId")), False))
                End If
                MyParms.Add(New ReportParameter("ProviderId", dropProvider.SelectedItem.Value, False))
                If dropVisit.Visible = True Then
                    MyParms.Add(New ReportParameter("FollowUpVisitId", dropVisit.SelectedItem.Value, False))
                End If
                MyParms.Add(New ReportParameter("FY", dropContractFY.SelectedItem.Value, False))

                ReportViewer1.ProcessingMode = ProcessingMode.Remote
                ReportViewer1.ServerReport.ReportServerUrl = New Uri(System.Configuration.ConfigurationManager.AppSettings("ReportServerURI"))
                ReportViewer1.ServerReport.ReportPath = Session("ReportsFolder") & "FReport"
                ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
                ReportViewer1.ServerReport.SetParameters(MyParms)
                ''#Code to convert the report to pdf 
                deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>"
                bytes = ReportViewer1.ServerReport.Render(format, deviceInfo, mimeType, encoding, extension, streamids, warnings)
                ReportViewer1.ServerReport.Refresh()
                Response.Buffer = True
                Response.Clear()
                Response.ContentType = mimeType
                Response.AddHeader("content-disposition", "attachment; filename=FReport." + extension)
                Response.BinaryWrite(bytes)

I read that the default length limit is 4MB. None of the reports by themselves are even over 350K. I'm wondering if this could be caused by a caching issue. I'm not an expert, so I need some guidance as to how best to solve the problem. I also want to understand why the issue is happening. Please note that only 2 reports are shown in the snippet - there are about 30+ reports in the full sub.

Thanks for your help.

edit - I tried the proposed solution, but it didn't help (I also tried the Fiddler route, but did not see anything glaring). I thought it might be best to clarify. The reports will run fine for a while, but the execution time gradually gets slower and slower until the application eventually displays the error. Does this shed any light on the problem?

TIA

+3  A: 

try increasing the following values in your web.config:

<httpRuntime maxRequestLength="204800" requestLengthDiskThreshold="204800" />
derek
Thanks for the help, but I'd like to know WHY it's happening. Since none of the reports exceed the 4MB limit (or even come close), I can only assume there is a bigger issue at hand. As a last resort, I'll implement your suggestion and give you credit for the answer.
mpminnich
my only suggestion would be to use Fiddler or some equivalent and try to inspect the response to see it's actual size and what may be bloating it.
derek
A: 

Have you tried logging the Request URLs to see if they are growing? Perhaps it is somewhere in that "ReportsFolder" session value or the extension that is being misset somewhere would be my guess.

JB King
+1  A: 

Ok, I figured it out...finally. Here's the cause (for anyone with a similar problem). The issue is viewstate. The reportviewer on the page is adding millions of bytes to viewstate, causing the issue. I disabled viewstate for the hidden reportviewer and no longer have the issue. Thank you to everyone for your help and suggestions.

mpminnich