Reputation: 6743
I am trying to export a Crystal Report to PDF. Here's the code (obviously passwords and server names and stuff have been changed to protect the innocent)...
public void RunReport(string outputFile, int cc, int yr, int wk)
{
ReportDocument rd = new ReportDocument();
rd.Load(FullFilePath("myreport.rpt"));
rd.Refresh();
rd.SetDatabaseLogon("userid", "password");
foreach (Table tbl in rd.Database.Tables)
{
tbl.LogOnInfo.ConnectionInfo.ServerName = "dbname";
tbl.LogOnInfo.ConnectionInfo.DatabaseName = "";
tbl.LogOnInfo.ConnectionInfo.UserID = "userid";
tbl.LogOnInfo.ConnectionInfo.Password = "password";
}
foreach (IConnectionInfo ci in rd.DataSourceConnections)
{
ci.SetLogon("userid", "password");
}
DiskFileDestinationOptions diskFileDestinationOptions = new DiskFileDestinationOptions();
ExportOptions exportOptions;
PdfRtfWordFormatOptions pdfFormatOptions = new PdfRtfWordFormatOptions();
diskFileDestinationOptions.DiskFileName = outputFile;
crExportOptions = rd.ExportOptions;
{
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
crExportOptions.DestinationOptions = diskFileDestinationOptions;
crExportOptions.FormatOptions = pdfFormatOptions;
}
SetCurrentValuesForParameterField(rd, "IP_COMP_CODE", cc);
SetCurrentValuesForParameterField(rd, "IP_YEAR", yr);
SetCurrentValuesForParameterField(rd, "IP_WEEK", wk);
rd.Export();
}
private void SetCurrentValuesForParameterField(ReportDocument reportDocument, string paramFieldName, int value)
{
ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
parameterDiscreteValue.Value = value.ToString();
ParameterValues currentParameterValues = new ParameterValues();
currentParameterValues.Add(parameterDiscreteValue);
reportDocument.DataDefinition.ParameterFields[paramFieldName].ApplyCurrentValues(currentParameterValues);
}
Now the weird part is, when I first wrote this code (and it was in SVN), it would give me a COM exception saying it was out of memory the first time I did an export (this was in an ASP.NET MVC app), but all subsequent exports (until I restarted the web app) would work just fine.
The error produced was:
First-chance exception at 0x75a2c41f in w3wp.exe: Microsoft C++ exception: _com_error at memory location 0x20dee4b0.
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in CrystalDecisions.CrystalReports.Engine.dll
An exception of type 'System.Runtime.InteropServices.COMException' occurred in CrystalDecisions.CrystalReports.Engine.dll but was not handled in user code
Additional information: Memory full.
Failed to export the report.
I posted on SAP's web site and their support guy offered some code changes which I included and then it stopped working entirely with the following error:
An exception of type 'CrystalDecisions.CrystalReports.Engine.DataSourceException' occurred in CrystalDecisions.ReportAppServer.DataSetConversion.dll but was not handled in user code
Additional information: Failed to load database information.
Error in File myreport {6DC42165-A38A-4CB2-85FD-A77389827FA9}.rpt:
Failed to load database information.
When I reverted the code changes back, it continued to give me this error (and has since). Now I can't export a report at all.
The changes he suggested resulted in this code:
ReportDocument rd = new ReportDocument();
rd.Load(FullFilePath("myreport.rpt"));
ConnectionInfo connectInfo = new ConnectionInfo()
{
ServerName = "dbname",
DatabaseName = "",
UserID = "userid",
Password = "password"
};
rd.SetDatabaseLogon("userid", "password");
foreach (Table tbl in rd.Database.Tables)
{
tbl.LogOnInfo.ConnectionInfo = connectInfo;
tbl.ApplyLogOnInfo(tbl.LogOnInfo);
}
Now SAP is saying they won't support me because I'm using VS.NET 2012, even though I'm not using any VS.NET integration, simply the SDK. They've been spectacularly unhelpful.
I'm running on Windows 7 64-bit. The Crystal Reports SDK I've installed is: CRforVS_redist_install_64bit_13_0_4.zip, available from their web site.
The database on the back end is Oracle and the client is 11g.
I've uninstalled and reinstalled both the Oracle client and Crystal Reports and have had no success. I simply cannot export a report any longer.
Upvotes: 0
Views: 11435
Reputation: 6743
I ended up having to do everything as 32-bit. I never could get the 64-bit crystal stuff working. Because of the terrible (rude) tech support, we're going to dump Crystal for SSRS.
Upvotes: 4