SAP Knowledge Base Article - Public

1853934 - Using Crystal Reports in a Visual Studio .NET web application, database connection is left open

Symptom

  • Viewing a Crystal report in a Visual Studio application, the database connection will not close
  • Thousands of connections on the database servers are left open even after the application is closed

Environment

  • SAP Crystal Reports, developer version for Microsoft Visual Studio
  • Microsoft Visual Studio 2010

Resolution

Store the ReportDocument object in HttpSession as given below:

 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public partial class _Default : System.Web.UI.Page
{
private ReportDocument hierarchicalGroupingReport;
private void ConfigureCrystalReports()
{
if(Session["hierarchicalGroupingReport"] == null)
{
hierarchicalGroupingReport = new ReportDocument();
hierarchicalGroupingReport.Load(Server.MapPath("Hierarchical Grouping.rpt"));
Session["hierarchicalGroupingReport"] = hierarchicalGroupingReport;
}
else
{
hierarchicalGroupingReport = (ReportDocument)Session["hierarchicalGroupingReport"];
}
crystalReportViewer.ReportSource = hierarchicalGroupingReport;
}
private void Page_Init(object sender, EventArgs e)
{
ConfigureCrystalReports();
}
}

Keywords

db vs cr4vs crvs closed terminated , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio