0

我正在尝试将 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 应用程序中) ),但所有后续导出(直到我重新启动网络应用程序)都可以正常工作。

产生的错误是:

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,但没有成功。我根本无法再导出报告。

4

1 回答 1

4

我最终不得不将所有事情都作为 32 位。我永远无法让 64 位水晶的东西工作。由于糟糕(粗鲁)的技术支持,我们将放弃 Crystal 用于 SSRS。

于 2013-01-03T15:20:01.173 回答