[英]Can't get a Crystal Report to export
我正在嘗試將Crystal報表導出為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應用程序中) ),但所有后續導出(直到我重新啟動網絡應用程序)都可以正常工作。
產生的錯誤是:
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。 他們非常無助。
我正在Windows 7 64位上運行。 我安裝的Crystal Reports SDK為:CRforVS_redist_install_64bit_13_0_4.zip,可從其網站上獲得。
后端的數據庫是Oracle,客戶端是11g。
我已經卸載並重新安裝了Oracle客戶端和Crystal Reports,但是都沒有成功。 我根本無法再導出報告。
我最終不得不做所有32位的事情。 我永遠無法使64位晶振工作。 由於技術的糟糕(粗魯)支持,我們打算將Crystal丟給SSRS。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.