on 08-02-2014 5:08 AM
We are having many clients that are running our program on Windows 7 64 bit platforms, our program that displays the report hangs our program when the user closes the report. I ran the latest SP9 and SP10 on the workstation and it still has the problem.
Windows 7 64 bit operating system.
Windows Form Application
I have wrote a very simple application and have isolated the problem to the dispose method.
DataSet ds = new DataSet();
DataTable dt = new DataTable("FRUIT");
DataColumn dc = new DataColumn("Type");
dt.Columns.Add(dc);
dc = new DataColumn("Color");
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr["Type"] = "Apple";
dr["Color"] = "Red";
dt.Rows.Add(dr);
dt.AcceptChanges();
ds.Tables.Add(dt);
CrystalReport2 RPT2 = new CrystalReport2();
RPT2.SetDataSource(ds);
crystalReportViewer1.ReportSource = RPT2;
if (crystalReportViewer1.ReportSource is CrystalReport2) // check if valid reference
{
CrystalReport2 rpt = crystalReportViewer1.ReportSource as CrystalReport2;
rpt.Database.Tables.Dispose();//When code reaches this point, the program locks up and freezes.
rpt.Database.Dispose();
rpt.Dispose();
}
crystalReportViewer1.Dispose();
crystalReportViewer1 = null;
this.Close();
Remove this line:
rpt.Database.Tables.Dispose();
You are setting the report to a dataset:
RPT2.SetDataSource(ds);
So Database.Tables is not in play at all. If you want to dispose of the data, you's be closing and disposing the dataset, not Database.Tables.
- Ludek
Senior Support Engineer AGS Product Support, Global Support Center Canada
Follow us on Twitter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, let's try this:
CrystalDecisions.CrystalReports.Engine.ReportDocument crReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
crReportDocument.Load(<path to your report);
crReportDocument.SetDataSource(ds);
CrystalReportViewer1.ReportSource = crReportDocument;
- Ludek
Hi Steven,
Your code is funny...
Why are you assigning the report to the viewer 2 times with different object names?
crystalReportViewer1.ReportSource = RPT2;
and then again...
CrystalReport2 rpt = crystalReportViewer1.ReportSource as CrystalReport2;
So this code is completely not needed:
if (crystalReportViewer1.ReportSource is CrystalReport2) // check if valid reference
{
CrystalReport2 rpt = crystalReportViewer1.ReportSource as CrystalReport2;
rpt.Database.Tables.Dispose();//When code reaches this point, the program locks up and freezes.
rpt.Database.Dispose();
rpt.Dispose();
}
Also, you should not be using Strongly typed reports.
Load them from the Hard drive with a full path:
rpt.Load(rptName.ToString(), OpenReportMethod.OpenReportByTempCopy);
Also, the reason the code is locking up is your data source is not correct, or same as the report.
Use a report with no data source and just a text object with "hello world" in it and try again. Comment out you set data source code too.
Also, if you put this in the same routine:
crystalReportViewer1.Dispose();
crystalReportViewer1 = null;
this.Close();
You will never see your report. Add a Close Button and move the code there.
And once again, you should not be using Strongly typed reports. Load the report off the HD
Since everyone else said it will also, don't dispose of the data source, CR will do that for you when you close the report.
Don
Instead of disposing everything one by one you could simply close and dispose the reportdocument object which would release the memory and will clean CR temp files.
instead of
CrystalReport2 rpt = crystalReportViewer1.ReportSource as CrystalReport2;
rpt.Database.Tables.Dispose();//When code reaches this point, the program locks up and freezes.
rpt.Database.Dispose();
rpt.Dispose();
try this
CrystalReport2 rpt = crystalReportViewer1.ReportSource as CrystalReport2;
rpt.Close();
rpt.Dispose();
- Bhushan
Senior Engineer
SAP Active Global Support
Follow us on Twitter
Got Enhancement ideas? Try the SAP Idea Place
Getting started and moving ahead with Crystal Reports .NET applications.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.