PC Review


Reply
Thread Tools Rate Thread

already an open DataReader associated with this Connection

 
 
mark
Guest
Posts: n/a
 
      1st Feb 2005
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
Guest
Posts: n/a
 
      1st Feb 2005
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!
***************************


"mark" wrote:

> 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
>

 
Reply With Quote
 
Guest
Posts: n/a
 
      1st Feb 2005
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?



>-----Original Message-----
>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!
>***************************
>
>
>"mark" wrote:
>
>> 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
>>

>.
>

 
Reply With Quote
 
mark
Guest
Posts: n/a
 
      1st Feb 2005
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?

>-----Original Message-----
>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!
>***************************
>
>
>"mark" wrote:
>
>> 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
>>

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
There is already an open DataReader associated with this Connection which must be closed first fniles Microsoft VB .NET 20 19th Dec 2006 08:59 PM
There is already an open DataReader associated with this Connection which must be closed first Rob Nicholson Microsoft ASP .NET 15 24th Sep 2005 06:18 PM
open DataReader associated with this Connection =?Utf-8?B?TWFnZGVsaW4=?= Microsoft ADO .NET 7 26th Aug 2004 11:43 PM
There is already an open DataReader associated with this Connection which must be closed first, AGAIN !!!!!! ItsMe Microsoft ADO .NET 4 19th Feb 2004 03:38 PM
There is already an open DataReader associated with this Connection James Brown Microsoft ASP .NET 1 26th Jun 2003 06:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:15 AM.