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.
这篇关于水晶报表——关闭数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:水晶报表——关闭数据库连接
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01