Crystal reports - close the database connection(水晶报表——关闭数据库连接)
问题描述
这是在 C#、Visual Studio 2008、VS2008 自带的水晶报表中
This is in C#, Visual Studio 2008, crystal reports that came with VS2008
我有一个位于 DLL 中的水晶报表查看器表单.DLL 负责加载水晶报表(基于报表文件名),并在窗体上显示报表.
I've got a crystal report viewer form that resides in a DLL. The DLL is responsible for loading the crystal report (based on report filename), and displaying the report on the form.
当我完成水晶报表时,我在加载的报表文档对象上调用 dispose.但是,数据库连接仍然存在.
When I'm done with the crystal report, i call dispose on the loaded reportdocument object. However, the database connection remains.
Crystal 似乎检测到(从我的主应用程序)到同一个数据库的其他连接,并保持其连接打开.当主应用程序数据库连接关闭时,水晶连接关闭.
Crystal seems to detect that there are other connections (from my main application) to the same database, and keeps its connection open. The crystal connection is closed when the main applications database connection is closed.
有什么方法可以强制水晶关闭其连接,而不关闭主应用程序数据库连接?
Is there any way to force crystal to close its connection, with out closing the main applications database connection?
推荐答案
标记代码似乎在一定程度上缓解了这种情况,虽然它有点倒退,应该是这样的:
Marks code seems to somewhat relieve the situation although it is a bit backwards, should be something like:
ReportDocument rd = (ReportDocument) viewer.ReportSource;
foreach (Table table in rd.Database.Tables)
table.Dispose();
viewer.ReportSource = null;
rd.Database.Dispose();
rd.Close();
rd.Dispose();
rd = (ReportDocument) viewer.ReportSource;
GC.Collect();
这对我来说并没有完全堵住漏洞,但确实有帮助.
This didn't completely plug the leak for me but certainly helped.
这篇关于水晶报表——关闭数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:水晶报表——关闭数据库连接
基础教程推荐
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 从 C# 控制相机设备 2022-01-01
- 将数据集转换为列表 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
