【发布时间】:2013-05-02 12:20:49
【问题描述】:
我在vs 2010 c#上使用水晶报告,我使用CR的rpt文档创建pdf文件。
我把这段代码放在 Windows 服务上,我的代码正常工作了 30 - 40 次,但是每次进度每 +5 +7 内存就会增加。
最后我得到这样的错误:加载文件失败!
我的代码:(我想我处置/关闭 conn 但如何)
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;
}
}
}
谢谢建议,请帮帮我
【问题讨论】:
-
这是代码中设置数据库登录的部分,而不是加载报告的部分(并且您的错误是“加载文件失败!”)。你可能会展示你工作的正确部分。
标签: c# visual-studio-2010 crystal-reports crystal-reports-2010