我正在尝试将Crystal Report导出为PDF。这是代码(显然密码和服务器名称和内容已被更改以保护无辜者)......
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);
}
现在奇怪的部分是,当我第一次编写这段代码(并且它在SVN中)时,它会给我一个COM异常,说我第一次执行导出时内存不足(这是在ASP中。 NET MVC应用程序),但所有后续导出(直到我重新启动Web应用程序)都可以正常工作。
产生的错误是:
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.
我发布在SAP的网站上,他们的支持人员提供了我包含的一些代码更改,然后它完全停止了以下错误:
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.
当我恢复代码更改时,它继续给我这个错误(并且从那以后)。现在我根本无法导出报告。
他建议的更改产生了以下代码:
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);
}
现在SAP说他们不会支持我因为我正在使用VS.NET 2012,即使我没有使用任何VS.NET集成,只需要SDK。他们一直非常无益。
我在64位Windows 7上运行。我安装的Crystal Reports SDK是:CRforVS_redist_install_64bit_13_0_4.zip,可从他们的网站获得。
后端的数据库是Oracle,客户端是11g。
我已经卸载并重新安装了Oracle客户端和Crystal Reports,但没有成功。我根本无法再导出报告。
答案 0 :(得分:4)
我最终不得不做32位的所有事情。我永远无法让64位水晶工作。由于可怕(粗鲁)的技术支持,我们将为SSRS转储Crystal。