cancel
Showing results for 
Search instead for 
Did you mean: 

Load Report Failed when setting the CrystalDecisions.Windows.Forms.CrystalReportViewer.ReportSource

caresreports
Explorer
0 Kudos

I have a .NET 4.6.2 Windows Forms based application, Visual Studio 2022 which allows a user to run several Crystal Reports.

This Windows form based application runs on the Windows 10/11 Desktop.

Each time a report is run, the following steps are performed.

There is a function called ConfigureCrystalReports

private string ConfigureCrystalReports()

{

_oReportDoc = new ReportDocument();

_oReportDoc.Load(@sReportPath);

_oReportDoc.VerifyDatabase();

_oReportDoc.ExportToDisk(ExportFormatType.CrystalReport, _sTmpReportPath);

_oReportDoc.Close();

_oReportDoc.Dispose();

GC.Collect();

}

Once ConfigureCrystalReports returns

a form which I will call ReportViewerControl is created. The forms wraps the CrystalDecisions.Windows.Forms.CrystalReportViewer.

Each time this ReportViewerControl is created, a CrystalDecisions.Windows.Forms.CrystalReportViewer is created and then the ReportSource is set to the path _sTmpReportPath which represents the path to the exported report file.

oReportViewerCtrl = new ReportViewerControl();

oReportViewerCtrl..SetViewerReport(_sTmpReportPath);

public partial class ReportViewerControl : UserTabbedDocument

{

public ReportViewerControl()

{

InitializeComponent(); // this will create the instance of the CrystalDecisions.Windows.Forms.CrystalReportViewer

}

public void SetViewerReport(string tmpReportPath)

{

crystalReportViewer.Error += CrystalReportViewer_Error;

crystalReportViewer.ReportSource = tmpReportPath;

}

private void CrystalReportViewer_Error(object source, CrystalDecisions.Windows.Forms.ExceptionEventArgs e)

{

string exceptionMsg = e.Exception.ToString();

string innerException = e.Exception.InnerException.ToString();

}

}

So I was on a much earlier release of the Crystal Framework but could always run report multiple reports without issues.

Now after I run 2-3 reports, when the line of code crystalReportViewer.ReportSource = tmpReportPath;

is executed, CrystalReportViewer_Error is called and the information in exceptionMsg and innerException is

CrystalDecisions.Shared.CrystalReportsException: Load report failed. ---> System.Runtime.InteropServices.COMException: The document is being opened.

at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options)

at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options)

at CrystalDecisions.ReportAppServer.ReportClientDocumentWrappe

To give more back on the overall look and feel of the Window in which the reports are display, every report has a tab. So you can run consecutive reports and each report

gets its own tab with a parent window. This was working find before the upgrade to the SP32 release.

Accepted Solutions (1)

Accepted Solutions (1)

caresreports
Explorer
0 Kudos

So after creating a test project to hand over the Crystal Report technical support, I found that a Window management framework that I was using created my issue. I switched from a SandDock framework into a TabControl/TabPage and had each TabPage create a CrystalReportViewer object. Once I did that, my issue went away.

I am considering this issue resolved.

Answers (2)

Answers (2)

0 Kudos

Sent a message to you.

It sounds like it could be a threading issue, is your application threaded?

CR runtime has a 3 CPL limit, meaning only 3 reports can be accessed at any time, a delay may be holding the report open causing the CPL limit to trigger.

It also sounds like it's a Windows Lock issue but test app may show use more.

Thanks again

Don

0 Kudos

Hi Rob,

I changed the Tag to CR for VS...

What version were you using previously?

Can you try setting your framework to 4.7.2 or 4.8?

I know we had some issues with 4.5 and 4.6 framework.

Are you setting your app to run in x64 or x86 mode?

Would it be possible to get a simplified test project that emulates your main app for me to test?

I'll send you a link to send it to me directly if you don't want it public...

The error suggests the report is still "busy" so it's not allowing you to open a new report. It could be a Windows back ground process not releasing the reports but just guess here...

Thanks

Don

caresreports
Explorer
0 Kudos

The version we came from was 13.0.20. The msi file we installed was CRRuntime_32bit_13_0_20.msi.

The Platform Target in the Build Panel (in the project settings) is x86.

I will try setting the framework to 4.7.2 or 4.8 and see if that helps.

Allow me to try out framework setting first and if that does not work, I can get you a sample project.

I will follow up as soon as I can. Thank you for the prompt response.

caresreports
Explorer
0 Kudos

So I'm trying to get something together for you and I also read over what you said

"The error suggests the report is still "busy" so it's not allowing you to open a new report. It could be a Windows back ground process not releasing the reports but just guess here.."

and letting that sink in.

So in my app, once the ReportDocument.Export is done, I have my code opening 6 previously generated .rpt files, one right after the other. They all open fine, I see all 6 tabs in the UI. So I have a feeling that the ReportDocument.Export may write out in an exclusive mode and then when the CrystalReportViewer class object goes to open the file, the logic sees an existing exclusive mode on it and says hey "Document is opened". It opens in exclusive mode because it needs to make sure it has a completed file and done some last minute write that could alter the contents.

I'm going to try an experiment. ReportDocument.Export is synchronous call. Once that completes and the code moves onto the next line, I'm going to copy that file to a new file and see what happens. The background processes in Crystal could very well be done writing out to the file but if there is exclusive mode file handle existing yet (some leak somewhere), perhaps a file copy to a secondary file and then opening that secondary file may work.

I will report back as to what I find.

caresreports
Explorer
0 Kudos

What I've tried

1) Switching to the new framework 4.8. That did not help.

2) as my program looped through each of the 6 files, just before the code called the CrystalReportViewer class object method .ReportSource= tmpReportPath;

I experiimented with

System.IO.FileStream stream = System.IO.File.Open(tmpReportPath, System.IO.FileMode.Open, System.IO.FileAccess.Write, System.IO.FileShare.None);

and the CrystalReportViewer_Error error handler was called and the exception message text was "Another process has this file open" vs "Document is opened". I wanted to at least prove that it has something to do with something tried to open that with an exclusive lock.

3) Another approach I tried was to change the ReportDocument.ExportToDisk to

Stream exportFile = _oReportDoc.ExportToStream(ExportFormatType.CrystalReport);

long reportLength = exportFile.Length;

byte[] bytesToWrite = new byte[exportFile.Length];

exportFile.Read(bytesToWrite, 0, (int)reportLength);

exportFile.Close();

exportFile.Dispose();

exportFile = null;

_oReportDoc.Close();

_oReportDoc.Dispose();

_oReportDoc = null;

GC.Collect();

File.WriteAllBytes(_sTmpExportReportPath, bytesToWrite);

File.Copy(_sTmpExportReportPath, _sTmpReportPath, true);

My intent here is to give the CrystalReportViewer class object a file that the ReportDocument export logic nows nothing about so that any kind of sharing lock can be taken out of the picture.

With this logic, I can a report or two fine, but on the 3rd or 4th consecutive report , I still get the CrystalReportView class object throwing the error with the exception text being. " CrystalDecisions.Shared.CrystalReportsException: Load report failed. ---> System.Runtime.InteropServices.COMException: The document is being opened.".

Don Williams, At this point, I'm going to get a project together for the Crystal Team to look at. I feel I've done as much troubleshooting as I can. You guys probably have symbols that can aid you in debugging. Hopefully you can reproduce this.