Crystal report from asp.net works then randomly stops

Enhanced Support
Enhanced Support used Ask the Experts™
on
Hi,

I have a problem with the crystal report viewer control when launched from an asp.net web page.

This will work absolutely fine for several days at a time on the production site, showing various reports correctly, but then they all just stop working, and present the user with a blank page when launched. Obviously the database and credentials, e.t.c do not change, the reports simply will not show until the server is restarted. I do not think it is a memory leak issue because the w3wp.exe service is not using an excessive amount of memory. I have also tried making a call to gc.collect to see if previous reports had been left in memory, but this made no difference. When it stops working, no connection is shown in SQL server activity monitor, so I don't think it's getting as far as a database query.

Developed in visual studio 2008, sql 2008 r2, crystal 2008.

My ASPX page is as per normal blank template with just this :-
<%@ Register Assembly="CrystalDecisions.Web, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"   Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<CR:CrystalReportViewer PrintMode="ActiveX" HasCrystalLogo="False" ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />

Open in new window


vb.net code behind in page.load (note the helpers class just provides relevant credentials).
        Dim Report As ReportDocument
        Report = New ReportDocument
        Report.Load(Hosting.HostingEnvironment.MapPath("~/App_reports/report1.rpt"))

        Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo
        Dim myTables As Tables = Report.Database.Tables
        Dim myTableLogonInfo As New TableLogOnInfo

        With myConnectionInfo
            .ServerName = Helpers.GetConfigSetting("CrystalDSN")
            .DatabaseName = Helpers.GetConfigSetting("DefaultDatabaseName")
            .UserID = Helpers.GetConfigSetting("DatabaseUser")
            .Password = Helpers.GetConfigSetting("DatabasePassword")
            .Type = ConnectionInfoType.SQL
        End With
        For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
            myTableLogonInfo = myTable.LogOnInfo
            myTable.LogOnInfo.ConnectionInfo.AllowCustomConnection = True
            myTableLogonInfo.ConnectionInfo = myConnectionInfo
            myTable.ApplyLogOnInfo(myTableLogonInfo)
            myTable.Location = Helpers.GetConfigSetting("DefaultDatabaseName") & ".dbo." & myTable.Location
        Next
        CrystalReportViewer1.ReportSource = Report

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Consultant
Most Valuable Expert 2011
Top Expert 2013
Commented:
When the users close a report are you cleaning up the report objects and disposing of them correctly?
Crystal does have a limit of connections.  Crystal also creates many temporary files that aren't cleaned out unless you properly close the report and dispose of the objects.

mlmcc

Author

Commented:
At what point can I clean up the report objects? I am launching the reports as a separate popup window so they have the full page for the preview (as the rest of my application works from a master page with a standard header/menu) - there is nothing else on the page which displays the report. The code (as posted) therefore runs on page.load but I cannot clean up here as it is needed to display to the user - however if the user just closes the popup browser window, I have no server side event in which to do any cleanup?
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
You may not be able to and if that is the issue then you may be stuck restarting the server.

There may be ways of cleaning the temp files through scripts but I don't know what they would be.

Why are you using this method of displaying the reports?

Could you spawn a separate application rather than just a page when you want to show a report?

mlmcc

Author

Commented:
OK I think I have a solution here. I have found the temp files, but even with a script they cannot be cleaned as they are in use, you were right, it is to do with objects not being released.

I think I can add a collection to the application, instatiated in the application startup in global.asax; when a report is run, I can add it to the collection as a key/value pair; if i find the user is already in the collection, I can get a reference to the report document and release that object from there before adding the new one. I'm pretty sure this will work, thanks for your help,

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial