cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Reports locks the program that is running the report on Windows 7

Former Member
0 Kudos

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();

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

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

Former Member
0 Kudos

I used Christy Dell-Stinnett suggestion by only calling Dispose on the rpt itself and not on the database part at all.  So I used this code she suggested

CrystalReport2 rpt = crystalReportViewer1.ReportSource as CrystalReport2;

rpt.Dispose();  //Still Locks up the Workstation.

former_member183750
Active Contributor
0 Kudos

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

0 Kudos

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

Answers (1)

Answers (1)

former_member188030
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

I was able to try this at the client site and on the  rpt.Close(); part of the code, we are still having the application hang.  Is there any other suggestions I could try?

Thanks.

DellSC
Active Contributor
0 Kudos

Try not explicitly disposing rpt.Database.  Instead, use Bhushan's suggestion and just close and dispose the report object, which should internally dispose of the database and its connection.

-Dell

Former Member
0 Kudos

I did use Bhushan's suggestion and it still makes the application hang.

CrystalReport2 rpt = crystalReportViewer1.ReportSource as CrystalReport2

rpt.Close();     //Hangs at this part of the code per Bhushan's suggestion.          

rpt.Dispose();

DellSC
Active Contributor
0 Kudos

And if you take out the  .Close() and just use .Dispose() what happens?

-Dell

Former Member
0 Kudos

Hi,

I was able to connected to the client and tried your suggestion of only calling the .Dispose() method and it still locks up the Windows 7 Machine.