如何找到打开的datareader [英] How do I find what datareader is open

查看:75
本文介绍了如何找到打开的datareader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在修改somebodies代码并在运行时获取datareader连接已经打开错误。整个代码都有sqldatareader。我想我已经关闭并处理了所有的读者,但有一个仍然打开,我找不到它。

在VB中,如何在捕获错误时找到打开的内容。



帮助

Hi,
I am amending a somebodies code and get a datareader connection is already open error when I run it. There are sqldatareader all over this code. I think I have closed and disposed of all the reader but there is one still open and I cannot find it.
In VB how can I find what is open when I capture the error.

Help

推荐答案

你不能。您将不得不进行代码审查才能找到它。没有什么可以告诉你在任何时间点DataReader在代码中的哪个位置都是打开的。
You can't. You're going to have to do a code review to find it. There is nothing that's going to tell you where in the code a DataReader is open at any point in time.


不确定是否可以 - 因为DataReader不会将自己与任何特定方法相关联名称甚至是变量名称我无法看到一种方法,你可以从代码中跟踪可能与实际的SqlDataReader对象不同的程序集。



但是,它在同一个SqlConnection上 - 或者你不会收到消息 - 所以你可以关闭连接并重新打开它,这会杀死datareader。如果它真的被使用了,你应该在家中注意到代码中其他地方会出现问题。



你所说的意味着连接被打开并保持开放的生命您的应用程序,并且SqlCommand / SqlDataReader对象根本没有被处置。这是糟糕的设计,并且往往会在生产中产生问题,因为它们是稀缺的资源,不应该被保留。我首先使用块在中包装现有的数据库代码,以强制关闭并配置你应该已经存在的。如果代码那么糟糕,我也会开始密切关注SqlCommand对象:它们很可能是通过字符串连接构建的,这非常非常危险!
Not sure you can - because the DataReader doesn't associate itself with any particular method name or even variable name I can't see a way you can "track back" from your code in potentially a different assembly to the actual SqlDataReader object.

However, it is on the same SqlConnection - or you wouldn't get the message - so you could just close the connection and reopen it, which would "kill" the datareader. If it's really being used, you should homefully notice that cause problems elsewhere in the code.

What you are saying implies that a connection is opened and left open for the life of your app, and that SqlCommand / SqlDataReader objects aren't being Disposed at all. That's poor design, and tends to give problems in production because they are scarce resources and shouldn't be held. I'd start by "wrapping" your existing DB code in using blocks to force the close and dispose you should have already. And if the code is that bad, I'd also start looking very closely at SqlCommand objects as well: chances are they are built by string concatenation, which is very, very dangerous!


这篇关于如何找到打开的datareader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆