cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Reports - Export as PDF to stream - The system cannot find the path specified

Former Member
0 Kudos

Hi,

I'm running a C# .NET application on Windows Server 2012 R2 with .NET Framework 4.5. This application depends on the Crystal Reports runtime engine for .NET Framework 4.

After setting up my report (initialising object, loading .rpt file, setting database connection details, passing parameters), I am then exporting this report to a stream, then copying to a memory stream.


MemoryStream memoryStream = new MemoryStream();

Stream exportStream = crystalReport.ExportToStream(ExportFormatType.PortableDocFormat);

exportStream.CopyTo(memoryStream);

This process hangs for a minute or so before producing this exception/stack trace


System.Runtime.InteropServices.COMException (0x80004005): The system cannot find the path specified.

   at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)

   at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)

   at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)

   at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options)

   at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportFormatType formatType)

I've checked the permission of the .rpt file it uses and it has permission to read these files for the user the process is running as.

I've also confirmed that the user has permission to read/write to "%temp%" which resolves to "\AppData\Local\Temp\1" for that user. As the code is executed it writes 4 files to this location, before cleaning up 3 of them as the exception is thrown. One empty file remains.

I've reinstalled/repaired both the 32 and 64 bit editions of the runtime, and have also installed the Microsoft Visual C++ 2005 redistributables including the security updates. I did not receive any DLL registration errors while installing on this server (though have in previous deployments which were missing the dependencies).

I'm at a loss as to where to look into next. Any help would be appreciated.

Thanks,

Brent.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Brent,

See this thread:

http://scn.sap.com/message/15657914#15657914

Don

Former Member
0 Kudos

Hi,

After reviewing that thread I can see there is a workaround that may/may not impact performance, however this is the original approach I'm using and still experiencing the error.

As an alternative approach I've avoiding exporting to a stream all together and instead writing the file directly to the disk.


crystalReport.ExportToDisk(ExportFormatType.PortableDocFormat, documentFilePath);

However I still receive the same exception


System.Runtime.InteropServices.COMException (0x80004005): The system cannot find the path specified.

   at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)

   at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)

   at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)

   at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)

   at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToDisk(ExportFormatType formatType, String fileName)

This is only occurring on a production server. If I run this locally with the same version of the Crystal Reports runtime engine I do not experience this error (in both writing to a stream and a file).

Thanks,

Brent

Former Member
0 Kudos

Hi,

The cause of the issue turned out to be improperly setting the database connection details in the report. Originally I was only doing this


crystalReport.SetDatabaseLogon(

Program.SystemSettings.DatabaseUsername,

Program.SystemSettings.DatabasePassword,

Program.SystemSettings.DatabaseServer,

Program.SystemSettings.DatabaseDomainDatabase);

I've since added this section to also apply to each table


ConnectionInfo connectionInfo = new ConnectionInfo();

connectionInfo.UserID = Program.SystemSettings.DatabaseUsername;

connectionInfo.Password = Program.SystemSettings.DatabasePassword;

connectionInfo.ServerName = Program.SystemSettings.DatabaseServer;

connectionInfo.DatabaseName = Program.SystemSettings.DatabaseDomainDatabase;

foreach (Table table in crystalReport.Database.Tables)

{

    table.LogOnInfo.ConnectionInfo = connectionInfo;

    table.ApplyLogOnInfo(table.LogOnInfo);

}

This has resolved the issue.

Without applying on table level the report was connecting using the credentials supplied during the creating on the report in the Crystal Reports designer. The production server does not have access to the development server. I was able to identify this connection using procmon.

Hope this helps someone else.

Thanks,

Brent.

0 Kudos

Thanks for the update Brent.

And remember also if you have subreports to scan the section for subreport objects and set the log on info the same way.

Don

Answers (3)

Answers (3)

Former Member
0 Kudos

You can also get this error when you have problem with the stored procedure your report is based on. For me it was a user defined function in SQL Server, and I forgot to enable CLR after installation.

Searched for this error for couple of hours.  Hope it helps someone

Former Member
0 Kudos

thanks!!, this solved my problem.

in my case the problem was with a HANA report.

former_member183750
Active Contributor
0 Kudos

Hi Brent

The search string 'crystal net memorystream' (search box in top right corner), comes up with the following KBA:

2105311 - ExportToStream throws exception in SP 12 in Crystal Reports for Visual Studio

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Former Member
0 Kudos

Hi,

I am not trying to directly cast the ExportToStream() return value to a MemoryStream, rather I am using the returned Stream and pushing the data into a new MemoryStream. As such I'm not encountering the cast exception that the support note describes.

Thanks,

Brent

adrikoopman
Explorer
0 Kudos

But what if you do an ExportToDisk (or plain Export with option DiskFileDestination? Even then the .NET Runtime calls the ExportToStream method:

Dim myExportOpts As New CrystalDecisions.Shared.ExportOptions

myExportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat

Dim myExportFormatOpts As CrystalDecisions.Shared.PdfFormatOptions = CrystalDecisions.Shared.ExportOptions.CreatePdfFormatOptions

myExportFormatOpts.CreateBookmarksFromGroupTree = False

myExportFormatOpts.UsePageRange = False

Dim myExportDestinationOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = CrystalDecisions.Shared.ExportOptions.CreateDiskFileDestinationOptions

myExportDestinationOpts.DiskFileName = FileName

myExportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat

myExportOpts.ExportFormatOptions = myExportFormatOpts

myExportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile

myExportOpts.ExportDestinationOptions = myExportDestinationOpts

.Export(myExportOpts)

Gives (after approx. 300 exports) the following traceback with a "The system cannot find the path specified" error:

at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)

at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)

at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)

at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)

at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export(ExportOptions options)

at MyApp.CrystalReport.SaveReport() in D:\Visual Studio 2010 projects\MyProject\MyApp\Forms\CrystalReport.vb:line 128

What to do now?

former_member183750
Active Contributor
0 Kudos

Are you closing and disposing the report objects one you are done with them?

What's the DS?

- Ludek

adrikoopman
Explorer
0 Kudos

Hi Ludek,

No, I keep the report open and refresh the parametervalues. However, an upgrade from SP12 to SP14 solved the problem.

- Adri