already an open DataReader associated with this Connection

M

mark

We are seeing a ton of this error:
There is already an open DataReader associated with this
Connection which must be closed first.


I've went through all code that uses a datareader and made
sure that we are calling the .close() method on the
readers once we're finished.
We use a custom framework for our data access, where we
inherit from a class which contains this code. In that
base class, it keeps a member variable for the connection
object, so it can be reused. Does anyone know of an issue
with doing this? That's all I can think of.
Here's our method that gets our connection object which is
used by our getreader method in our base class.

Protected Overrides Function getConnection() As
IDbConnection
If mobjConnection Is Nothing Then
mobjConnection = New SqlConnection
(ConnectionString)
mobjConnection.Open()
Else
If mobjConnection.State <>
ConnectionState.Open Then
Try
mobjConnection.Open()
Catch ex As Exception
End Try
End If
End If
Return mobjConnection
End Function
 
G

Guest

If you are inheriting, make sure you close() and/or dispose() on the base
class from the derived class.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
G

Guest

we have a try, catch, finally around our derived class
code that gets the datareader from the base class.
In the finally, we close the reader, close the connection
and set the connection=nothing.

Any other ideas?
 
M

mark

oh, are you saying that we shouldn't call the
datareader.close() on the derived class? Call a base
class method? If so, why would that matter?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top