0

我使用vs 2010 c#的水晶报表,并使用CR的rpt文档创建PDF文件。Crystal Reports加载报告文档失败

我把这段代码放在windows服务上,我的代码正常工作30 - 40次,但随后内存每上升+5 +7就会上升。

最后我得到这样的错误:加载文件失败!

我的代码:(我想我处理/关闭康恩却怎么)

 private void ReportLogin(ReportDocument crDoc, string Database, string Server, string UserID, string Password) 
    { 
     try 
     { 
      crConnectionInfo = new ConnectionInfo(); 
      crConnectionInfo.ServerName = Server; 
      crConnectionInfo.DatabaseName = Database; 
      crConnectionInfo.UserID = UserID; 
      crConnectionInfo.Password = Password; 

      crDatabase = crDoc.Database; 
      crTables = crDatabase.Tables; 

      foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables) 
      { 
       crTableLogonInfo = crTable.LogOnInfo; 
       crTableLogonInfo.ConnectionInfo = crConnectionInfo; 
       crTable.ApplyLogOnInfo(crTableLogonInfo); 
      } 
     } 
     catch (Exception x) 
     { 
      throw x; 
     } 
    } 

    private void _CrystalReport(string RptFilePath) 
    { 

     reportDocument = LoadDoc(RptFilePath); 

     RptParamsWithType = new Dictionary<string, string>(); 

     if (reportDocument.ParameterFields.Count > 0) 
     { 
      foreach (ParameterField pField in reportDocument.ParameterFields) 
      { 
       RptParamsWithType.Add(pField.Name,    pField.ParameterValueType.ToString().Replace("Parameter", "")); 
      } 
     } 
    } 

负载功能:

private ReportDocument LoadDoc(string RptFilePath) 
    { 
     try 
     { 
      reportDocument = new ReportDocument(); 
      reportDocument.Load(RptFilePath); 

      return reportDocument; 

     } 
     catch (Exception x) 
     { 
      throw x; 
     } 

    } 

我的功能,去年堪称是创建PDF:

 public MemoryStream asPdf 
    { 
     get 
     { 
      using (TempMemoryStream = (MemoryStream)reportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)) 
      { 
       return TempMemoryStream; 
      } 
     } 
    } 

谢谢建议,帮我看看

+0

这是你的代码的一部分,你设置的数据库登录,而不是在这里装载的报告(和你的错误是“装载文件失败!”)的一部分。你可能会展示你的工作的正确部分。 – 2013-05-08 10:06:08

回答

0

我转换我的代码就像这个样本,它的工作原理!

using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.Text; 
using CrystalDecisions; 
using CrystalDecisions.CrystalReports; 
using CrystalDecisions.CrystalReports.Engine; 

namespace Test.Utilities 
{ 
    public class ReportFactory 
    { 
     protected static Queue reportQueue = new Queue(); 

     protected static ReportClass CreateReport(Type reportClass) 
     { 
     object report = Activator.CreateInstance(reportClass); 
     reportQueue.Enqueue(report); 
     return (ReportClass)report; 
     } 

    public static ReportClass GetReport(Type reportClass) 
    { 
     //75 is my print job limit. 
     if (reportQueue.Count > 75) ((ReportClass)reportQueue.Dequeue()).Dispose(); 
     return CreateReport(reportClass); 
    } 
    } 
} 

Original Link

0
private void LoadReport() 
    { 
     doc = new ReportDocument(); 
     doc.Load(Server.MapPath("CrSalesReport.rpt")); 
     doc.SetDatabaseLogon(AppConfig.ReportServerDSUserName, AppConfig.ReportServerDSPassword, AppConfig.ReportServerDomain, "TexERP", false); 

    } 

尝试使用数据库登录

+0

我不使用CrystalReportViewer.Its只有DLL,它返回我的PDF流。 – Mennan 2013-05-08 10:48:46

0

这个代码试试这个代码

ReportDocument crystalReport = new ReportDocument(); 
crystalReport.Load(Server.MapPath("CrystalReport.rpt")); 
crystalReport.SetDatabaseLogon("username", "password", @"server name", "DB name"); 
CrystalReportViewer1.ReportSource = crystalReport; 

希望它可以帮助你。

+0

如果仍然存在,这可能是权限issue.For请参阅该链接[链接](http://www.codeproject.com/Tips/297119/Crystal-Reports-Fix-for-Load-report-failed-错误) – 2013-05-08 11:29:32

+0

我的代码在2-3小时内正常工作。但有内存泄漏问题 – Mennan 2013-05-08 11:33:17

+0

因此删除临时文件是因为rpt文件是在临时文件文件夹中创建的副本。 – 2013-05-08 11:38:15