I am new to crystal reports. I have been having this problem for quite some time and can’t seem to solve it. What I am doing is running a report and sending back the generated PDF in the response.
The problem is, when I run the asp.net page (which runs the report) from the browser it works fine for the first or second time but then after that, the browser just keeps waiting and I do not get any response back from the server, not even an error! It just keeps loading for a long time. I even did a clean re-install of the server but still have the same issue. I was not having this problem during initial testing of this page.
Crystal reports is being unpredictable and I am not sure if this is because the reports are not being closed properly or the connection is not proper.
Windows Server 2003 – IIS
Here is the vb.net page –
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim connectionInfo As New ConnectionInfo
connectionInfo.ServerName = "UID=abc;PWD=abc;Driver= {SQL Server};Server=" & Page.Request.QueryString("server") & ";Database=" & Page.Request.QueryString("database")
Using report As New ReportDocument
report.Load(Server.MapPath("/report/Crystal/test.rpt"))
report.FileName = Server.MapPath("/report/Crystal/test.rpt")
SetDBLogonForReport(connectionInfo, report)
report.SetParameterValue("param1", Page.Request.QueryString("param1"))
Dim oStream As New MemoryStream()
oStream = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.BinaryWrite(oStream.ToArray())
report.Close()
End Using
Response.Flush()
Response.End()
End Sub
Private Sub SetDBLogonForReport(ByVal connectionInfo As ConnectionInfo, ByVal reportDocument As ReportDocument)
Dim tables As Tables
tables = reportDocument.Database.Tables
For Each table As CrystalDecisions.CrystalReports.Engine.Table In tables
Dim tableLogonInfo As New TableLogOnInfo
tableLogonInfo = table.LogOnInfo
tableLogonInfo.ConnectionInfo = connectionInfo
table.ApplyLogOnInfo(tableLogonInfo)
Next
End Sub
</div>
</form>
First off, put the call to report connection in the Page_Init() event, not Page_Load(). Prior to .NET 2005 it was okay to put it in Page_Load(). But now they changed how memory is managed and this can give you random errors depending upon the state of the CrystalReportViewer’s memory. Putting it in Page_Init() is safe all the time.
Secondly, I would do is remove the code:
CrystalReportViewer1.DataBind();
I would also remove the RefreshReport() call b/c it refreshes itself automatically when you assign the report object to it. But it doesn’t hurt to have it. Either way, definitely get rid of the .DataBind() call.
Hopefully these changes will get your application back to working.
For more detail Please check below link I face same problem year ago. Hope it’s helpful
LInk