PC Review


Reply
Thread Tools Rate Thread

Sql objConnection woes

 
 
=?Utf-8?B?SlA=?=
Guest
Posts: n/a
 
      3rd Apr 2006
I have a class method that returns a DataReader

SqlDataReader parentReader = class.GetResults("55");
if(parentReader.Read())
{
..
..
}


public SqlDataReader GetResults(string County)
{
SqlDataReader myreader= My SQL statements
..
..
..
objConnection.Dispose(); //Problem is here
return myReader
}

The prob is if the parant code attempts to read from myReader, it says it
cant b/c the datareader is closed. Yet at this point the fact that the
connection created in the child class was disposed shouldnt affect a
datareader thats already loaded. The connection was local to the child class,
why should the parent datareader care? Whats the problem? If I remove the
dispose method, everything works, but I run the risk of running out of
connections in the SQL pool b/c the code is called many times.
--
JP
..NET Software Develper
 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      3rd Apr 2006
A DataReader maintains a constant connection to the DataStore, as it only
fetches one row at a time. Therefore, as long as you are using the
DataReader, the Connection must remain opened.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"JP" <(E-Mail Removed)> wrote in message
news:EF0609A9-835A-421A-8324-(E-Mail Removed)...
>I have a class method that returns a DataReader
>
> SqlDataReader parentReader = class.GetResults("55");
> if(parentReader.Read())
> {
> .
> .
> }
>
>
> public SqlDataReader GetResults(string County)
> {
> SqlDataReader myreader= My SQL statements
> .
> .
> .
> objConnection.Dispose(); //Problem is here
> return myReader
> }
>
> The prob is if the parant code attempts to read from myReader, it says it
> cant b/c the datareader is closed. Yet at this point the fact that the
> connection created in the child class was disposed shouldnt affect a
> datareader thats already loaded. The connection was local to the child
> class,
> why should the parent datareader care? Whats the problem? If I remove the
> dispose method, everything works, but I run the risk of running out of
> connections in the SQL pool b/c the code is called many times.
> --
> JP
> .NET Software Develper



 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      3rd Apr 2006
See :
http://msdn.microsoft.com/library/de...classtopic.asp

The DataReader is actually connected and needs the connection to be open.

--
Patrice

"JP" <(E-Mail Removed)> a écrit dans le message de news:
EF0609A9-835A-421A-8324-(E-Mail Removed)...
>I have a class method that returns a DataReader
>
> SqlDataReader parentReader = class.GetResults("55");
> if(parentReader.Read())
> {
> .
> .
> }
>
>
> public SqlDataReader GetResults(string County)
> {
> SqlDataReader myreader= My SQL statements
> .
> .
> .
> objConnection.Dispose(); //Problem is here
> return myReader
> }
>
> The prob is if the parant code attempts to read from myReader, it says it
> cant b/c the datareader is closed. Yet at this point the fact that the
> connection created in the child class was disposed shouldnt affect a
> datareader thats already loaded. The connection was local to the child
> class,
> why should the parent datareader care? Whats the problem? If I remove the
> dispose method, everything works, but I run the risk of running out of
> connections in the SQL pool b/c the code is called many times.
> --
> JP
> .NET Software Develper



 
Reply With Quote
 
John Bailo
Guest
Posts: n/a
 
      3rd Apr 2006
JP wrote:

> The prob is if the parant code attempts to read from myReader, it says it
> cant b/c the datareader is closed. Yet at this point the fact that the
> connection created in the child class was disposed shouldnt affect a
> datareader thats already loaded. The connection was local to the child
> class, why should the parent datareader care? Whats the problem? If I
> remove the dispose method, everything works, but I run the risk of running
> out of connections in the SQL pool b/c the code is called many times.


You should serialize the data either to XML ( ExecuteXML ) or store the
contents to a DataSet.

--
http://www.you-read-it-here-first.com
....fueled by Texeme Textcasting...
 
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
objConnection.Open() is highlighted green ryguy7272 Microsoft VB .NET 3 26th Jul 2009 06:37 PM
WU Woes Roger Fink Microsoft Windows 2000 11 2nd Jun 2007 02:25 AM
OST woes SusieQ Microsoft Outlook Discussion 4 22nd Jun 2004 07:33 PM
VPN Woes Also.....Please Help Rose Windows XP Networking 1 30th May 2004 01:21 PM
NIC woes =?Utf-8?B?cm9kbmV5Mjc0MDU=?= Windows XP Networking 0 7th Mar 2004 06:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:49 PM.