Crystal Report返回“无效的子报表名称”。当C#应用程序创建报告时

时间:2019-04-30 20:54:57

标签: c# crystal-reports

我创建了一个生成Crystal Report的C#应用​​程序。在我的本地计算机上测试时,一切正常。将应用程序部署到服务器时,出现错误消息

“文件MyStatement 9272_6832_ {19C497DB-52A4-4A4F-B642-5B31AF3F710D} .rpt中的错误: 无效的子报表名称。 System.Runtime.InteropServices.COMException(0x80000232):文件MyStatement 9272_6832_ {19C497DB-52A4-4A4F-B642-5B31AF3F710D} .rpt中的错误: 无效的子报表名称。“

该应用程序应该通过批处理排队过程生成语句,并且一旦创建报告,就会向人们发送电子邮件。它可以在我的本地虚拟机上运行,​​但不能在远程服务器上运行。 MyStatement.rpt和远程服务器上的子报表文件都存在于远程服务器上。因此,我不确定为什么会引发“无效的子报表名称”。

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
private void generateCrystalReport(string filename, string selection, string reportName)
{
    string reportPath;
    string exportPath;
    reportPath = ConfigurationManager.AppSettings.Get("report_path");
    exportPath = ConfigurationManager.AppSettings.Get("export_path");

    ReportDocument rd = new ReportDocument();
    try
    {
        rd.Load(reportPath + reportName);

        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
        Tables CrTables = rd.Database.Tables;

        foreach (Table tbl in CrTables)
        {
            var tblLogInf = tbl.LogOnInfo;
            crConnectionInfo.ServerName = ConfigurationManager.AppSettings.Get("db_server");
            crConnectionInfo.DatabaseName = "";
            crConnectionInfo.UserID = ConfigurationManager.AppSettings.Get("cr_user");
            crConnectionInfo.Password = ConfigurationManager.AppSettings.Get("cr_pw");
            crtableLogoninfo.ConnectionInfo = crConnectionInfo;
            tbl.ApplyLogOnInfo(tblLogInf);
        }
        rd.RecordSelectionFormula = selection;

        ExportOptions CrExportOptions;
        DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
        PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
        CrDiskFileDestinationOptions.DiskFileName = exportPath + filename;
        CrExportOptions = rd.ExportOptions;
        {
            CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
            CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
            CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
            CrExportOptions.FormatOptions = CrFormatTypeOptions;
        }
        rd.Export();
        rd.Close();
    }
    catch (Exception ex)
    {
        rd.Close();
        throw ex;
    }
}

0 个答案:

没有答案
相关问题