问题
I use crystal reports on vs 2010 c#, and i create pdf files using rpt documents of CR.
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 !
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", ""));
}
}
}
Load Function:
private ReportDocument LoadDoc(string RptFilePath)
{
try
{
reportDocument = new ReportDocument();
reportDocument.Load(RptFilePath);
return reportDocument;
}
catch (Exception x)
{
throw x;
}
}
My function that last called is create pdf:
public MemoryStream asPdf
{
get
{
using (TempMemoryStream = (MemoryStream)reportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat))
{
return TempMemoryStream;
}
}
}
Thanks Advice, help me plz
回答1:
Try This code
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("CrystalReport.rpt"));
crystalReport.SetDatabaseLogon("username", "password", @"server name", "DB name");
CrystalReportViewer1.ReportSource = crystalReport;
Hope It helps you.
回答2:
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);
}
}
}
Original Link
回答3:
private void LoadReport()
{
doc = new ReportDocument();
doc.Load(Server.MapPath("CrSalesReport.rpt"));
doc.SetDatabaseLogon(AppConfig.ReportServerDSUserName, AppConfig.ReportServerDSPassword, AppConfig.ReportServerDomain, "TexERP", false);
}
Try this code for Database Logon
来源:https://stackoverflow.com/questions/16437812/crystal-reports-load-reportdocument-failed