水晶报表——关闭数据库连接

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.

这篇关于水晶报表——关闭数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)