Click here to Skip to main content
15,896,429 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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
Posted

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.
 
Share this answer
 
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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900