Re: streaming reports from report services
Brought to you by:
wrowe
From: David M. <wo...@su...> - 2008-10-21 18:39:11
|
<HTML> <P>Pasted below is how I resolved my issue. Setting the CONTENTTYPE property on the response took care of it. A boolean is declared at top then tested in the render routine. FLUSH, CLOSE, and END should not be used since everything will happen correctly as page processing is allowed to complete normally. Thanks for the assistance.</P> <P> Private NoRender As Boolean = False</P> <P> Private Sub OnCallReport(ByVal tit$, ByVal sql$, ByVal connect As Data.SqlClient.SqlConnection)<BR> UserLog("report", "OnCallReport:" & tit, ui.UserID, Request, connect)<BR> Dim localReport As New Microsoft.Reporting.WebForms.LocalReport<BR> localReport.ReportPath = Server.MapPath("~/OnCallReport01.rdlc")<BR> Dim command As New Data.SqlClient.SqlCommand(sql & " ORDER BY InSort", connect)<BR> Dim reader As Data.SqlClient.SqlDataReader = command.ExecuteReader<BR> localReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("DataSet1_DataTable1", reader))<BR> Dim parameter() As Microsoft.Reporting.WebForms.ReportParameter = {New Microsoft.Reporting.WebForms.ReportParameter("Report_Parameter_0", tit)}<BR> localReport.SetParameters(parameter)<BR> SubReportConnect = New Data.SqlClient.SqlConnection(DefaultConnect)<BR> SubReportConnect.Open()<BR> SubReportCommand = New Data.SqlClient.SqlCommand("", SubReportConnect)<BR> AddHandler localReport.SubreportProcessing, AddressOf OnCallReportSubreportProcessingEventHandler<BR> Dim bytes As Byte() = localReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)<BR> If Not IsNothing(SubReportReader) Then SubReportReader.Close()<BR> SubReportReader = Nothing<BR> SubReportConnect.Close()<BR> SubReportConnect = Nothing<BR> reader.Close()<BR> reader = Nothing<BR> Response.Clear()<BR> Response.ContentType = "application/x-pdf"<BR> Response.AddHeader("content-disposition", "attachment; filename=OnCallReport.pdf")<BR> Response.BinaryWrite(bytes)<BR> NoRender = True<BR> End Sub</P> <P> Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)<BR> If NoRender Or (Not Response.IsClientConnected) Then<BR> writer = Nothing<BR> Exit Sub<BR> End If<BR> writer.InnerWriter.Close()<BR> Dim sw As New IO.StringWriter<BR> writer.InnerWriter = sw<BR> MyBase.Render(writer)<BR> writer.Close()<BR> Response.Write(EditMenu(sw.ToString))<BR> End Sub<BR> </P> <P><BR> <BR> -- <BR> dgm <BR> <BR> <BR> <B>On Tue Oct 21 11:24 , David McDivitt <WO...@SU...>sent:<BR> <BR> </B></P> <BLOCKQUOTE style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #f5f5f5 2px solid; MARGIN-RIGHT: 0px"> <P>I'm getting there but still don't have it. Instead of using the END method on the response I used FLUSH followed with CLOSE. The report did stream to the client at that point, and the open, save, cancel dialog appeared. But when I clicked open, Adobe said the report was corrupted. Upon examining with notepad, the entire report was there, but followed with page output beginning with doctype and the whole nine yards. If deleted from the file, Adobe would display the report just fine!</P> <P>So I tried to see if I could stop output of the page. Obviously the CLOSE method on the response is not really closing the socket as the documentation says. I declared a common boolean value to be set by the report method, and if found in the render method, rendering was skipped. That does not work. Unless the page is allowed to render in the normal fashion, Apache sends an error page to the client saying the server is misconfigured. I tried substituting report content at the point of rendering, but get the same Apache error page.</P> <P>It would seem Apache is buffering the output and only sends the output if constructed properly. Otherwise it sends nothing generated by ASP.NET and sends the error page instead.</P> <P>I don't know how Apache knows whether the ASP.NET page did a normal page rendering. If bytes are written to the response, that should be the way it is. Apache must be examining the outgoing headers. But, Apache must not be examining the start of the stream, but the entire stream, since Apache let the stream pass even if normal page rendering was at the end.</P> <P>To resolve this I need to know exactly what Apache needs to see in the stream to approve it. I can also cancel normal page rendering, to leave the report, only. Maybe Apache doesn't allow the kind of stream I'm trying to write. Is there a validation feature I can turn off?<BR> <BR> -- <BR> dgm <BR> </P></BLOCKQUOTE></HTML> <BR> |