Crystal Reports加载reportDocument失败 [英] Crystal Reports load reportDocument failed

查看:1948
本文介绍了Crystal Reports加载reportDocument失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用水晶报告vs 2010 c#,并使用CR的rpt文档创建pdf文件。

I use crystal reports on vs 2010 c#, and i create pdf files using rpt documents of CR.

我把这个代码放在windows服务上,我的代码工作正常

I put this code on windows service,my code works normally for 30 - 40 times but then memory is rising per +5 +7 each progress.

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

Last i get error like this: load file is failed !

我的代码:(我认为我处理/关闭conn但如何)

My code: (i think i dispose/close conn but how)

     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;
        }

    }

我最后调用的函数是create pdf:

My function that last called is create pdf:

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

感谢建议,帮助我

推荐答案

我转换了我的代码,样例和它的工作原理!

i converted my code like this sample and it works!

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);
    }
  } 
}

原始链接

这篇关于Crystal Reports加载reportDocument失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆