Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Crystal Reports无法在ReportDocument.Load阶段打开连接。_C#_.net_Crystal Reports - Fatal编程技术网

C# Crystal Reports无法在ReportDocument.Load阶段打开连接。

C# Crystal Reports无法在ReportDocument.Load阶段打开连接。,c#,.net,crystal-reports,C#,.net,Crystal Reports,我目前面临Crystal Reports的一个问题,因此我们不断出现以下错误: PDF error: Failed to open the connection. Failed to open the connection. 4250901051516FA90CB6FED9F270A2A7 11952_8824_{CD4A46B0-F17C-4675-94B3-5F200A267CCF}.rpt InnerException: Failed to open the connection. Fa

我目前面临Crystal Reports的一个问题,因此我们不断出现以下错误:

PDF error: Failed to open the connection. Failed to open the connection. 4250901051516FA90CB6FED9F270A2A7 11952_8824_{CD4A46B0-F17C-4675-94B3-5F200A267CCF}.rpt  InnerException: Failed to open the connection. Failed to open the connection. 4250901051516FA90CB6FED9F270A2A7 11952_8824_{CD4A46B0-F17C-4675-94B3-5F200A267CCF}.rpt
实际上,我们已经创建了一个Crystal Reports处理器服务,Windows任务调度器可以运行该服务。此服务运行报表,将报表导出为PDF格式,将PDF报表作为电子邮件发送,并存储在中心位置

此服务对于某些报告工作正常-但是,该服务在调试模式下工作不好,并不断向我们提供此错误。即使对于似乎正常工作的报告,也发生了此错误

此异常总是发生在Export()方法阶段的末尾。但是,我注意到,当ReportDocument.HasRecords属性指示内部异常时,此异常会在ReportDocument.Load(thisCrystalDocument)处出现

我的设置如下: VS2013 Professional、Crystal Reports 2011、Crystal Reports 2011 SP8更新、SAP Crystal Reports runtime engine for.NET Framework 32位(v15)和SQL Server 2008 R2 32位。这不是ASP.NET项目

一些代码片段:

public CrystalReportGenerator(string reportLocation, string crystalParameters)
    {
      this.reportDocument = new ReportDocument();
      if (!File.Exists(reportLocation))
      {
        throw new Exception(String.Format("Report at '{0}' does not exist.", reportLocation));
      }

      // Cache report file
      var cacheFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + CrystalReportGenerator.cacheSubfolder);
      if (!Directory.Exists(cacheFolder))
      {
        Directory.CreateDirectory(cacheFolder);
      }
      var cachedLocation = Path.Combine(cacheFolder, reportLocation.GetMd5Sum()) + ".rpt";
      if (!File.Exists(cachedLocation))
      {
        File.Copy(reportLocation, cachedLocation, false);
      }

      // Generate report
      this.reportDocument.Load(cachedLocation);
      this.SetParameters(crystalParameters);

      // Override existing database login for report
      this.reportDocument.SetDatabaseLogon(CrystalReportGenerator.sqlUser, CrystalReportGenerator.sqlPassword, CrystalReportGenerator.sqlHost, CrystalReportGenerator.sqlDatabase, false);

      // Override existing database login for subreport(s)
      if (this.reportDocument.Subreports.Count > 0)
      {
        for (int i = 0; i < this.reportDocument.Subreports.Count; i++)
        {
          this.reportDocument.Subreports[i].SetDatabaseLogon(CrystalReportGenerator.sqlUser, CrystalReportGenerator.sqlPassword, CrystalReportGenerator.sqlHost, CrystalReportGenerator.sqlDatabase, false);
        }
      }
    }

private static void GenerateReport(string reportLocation, string reportTitle, string reportParameters, string outputLocation = null, string outputFormat = null, MailMessage message = null)
    {
      var isTempFile = false;

      // Generate report
      using (var generator = new CrystalReportGenerator(reportLocation, reportParameters))
      {
        if (String.IsNullOrWhiteSpace(outputLocation))
        {
          outputLocation = Path.GetTempFileName();
          isTempFile = true;
        }
        else
          outputLocation = outputLocation.ConvertDateTimeReference();

        generator.Export(outputLocation, outputFormat);

        // Send mail message
        if (message != null)
        {
          using (var attachment = new Attachment(outputLocation)
          {
            Name = String.Format("{0}.{1}", reportTitle.ConvertDateTimeReference(), outputFormat.Replace("-DATA", "").ToLower())
          })
          {
            message.Attachments.Add(attachment);
            Emailer.SendMailMessage(message);
          }
        }

        // Clean up temp file
        if (isTempFile && File.Exists(outputLocation))
        {
          File.Delete(outputLocation);
        }
      }
    }

private void Export(string outputLocation, string outputFormat)
    {
      ExportOptions exportOptions = this.reportDocument.ExportOptions;
      exportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
      exportOptions.DestinationOptions = new DiskFileDestinationOptions
      {
        DiskFileName = outputLocation
      };

      switch (outputFormat.ToUpper())
      {
        case "XLS-DATA":
          {
            exportOptions.ExportFormatType = ExportFormatType.ExcelRecord;
            exportOptions.FormatOptions = new ExcelFormatOptions();
            break;
          }
        case "XLS":
        case "XLSX":
          {
            exportOptions.ExportFormatType = ExportFormatType.ExcelWorkbook;
            exportOptions.FormatOptions = new ExcelFormatOptions();
            break;
          }
        case "PDF":
        default:
          {
            exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
            exportOptions.FormatOptions = new PdfRtfWordFormatOptions();
            break;
          }
      }
      this.reportDocument.Export();
    }
公共CrystalReportGenerator(字符串报告位置,字符串crystalParameters) { this.reportDocument=新的reportDocument(); 如果(!File.Exists(reportLocation)) { 抛出新异常(String.Format(“位于{0}的报表不存在。”,reportLocation)); } //缓存报告文件 var cacheFolder=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+CrystalReportGenerator.cacheSubfolder); 如果(!Directory.Exists(cacheFolder)) { CreateDirectory(cacheFolder); } var cachedLocation=Path.Combine(cacheFolder,reportLocation.GetMd5Sum())+“.rpt”; 如果(!File.Exists(cachedLocation)) { File.Copy(reportLocation,cachedLocation,false); } //生成报告 此.reportDocument.Load(缓存位置); 此参数为.SetParameters(crystalParameters); //覆盖报表的现有数据库登录 this.reportDocument.SetDatabaseLogon(CrystalReportGenerator.sqlUser、CrystalReportGenerator.sqlPassword、CrystalReportGenerator.sqlHost、CrystalReportGenerator.sqlDatabase,false); //覆盖子报表的现有数据库登录 如果(this.reportDocument.Subreports.Count>0) { for(int i=0;i 除此之外,我还注意到ReportDocument.HasRecords总是抛出异常


如果这个问题听起来有点愚蠢,我会提前道歉。这是我第一次尝试Crystal Reports,我非常感谢那些在这方面比我更有经验的人的智慧。多谢各位

在进一步检查了每个myreportorun.rpt文件之后,我重置了数据库连接字符串并刷新了每个报告,然后再次运行我的应用程序。这被证明是很有帮助的,因为它在以后工作了很多。

您是否尝试在编辑器中检查crystal report的预览,它会引发异常?crystal report的动态导出(这里是c#)的问题是,它通常会在导出行中引发错误。例如,如果您缺少参数,它将传递该代码,并在导出行(我的问题)抛出一个错误。我唯一应该做的事