473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Sql objConnection woes

JP
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
Apr 3 '06 #1
3 1070
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" <JP@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
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

Apr 3 '06 #2
See :
http://msdn.microsoft.com/library/de...classtopic.asp

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

--
Patrice

"JP" <JP@discussions.microsoft.com> a écrit dans le message de news:
EF**********************************@microsoft.com...
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

Apr 3 '06 #3
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...
Apr 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mark | last post by:
O, woe is me, to have seen what I have seen, see what I see! (That's Shakespeare for those who were wondering what I'm on about) I am "having fun" with cookies. And I wonder if I have...
0
by: Cedric | last post by:
This is a 3 weeks old problem, but having found a solution (and having looked for one here, finding only this message), I'm replying now. From: Jive (someone@microsoft.com) Subject: Upgrade...
3
by: Angel Cat | last post by:
Trying to get my jobs to send mail when job fails. Should be easy but it's giving me headache Had a whole slew of issues. Outlook is installed with a n outlook mail profile set up that can...
2
by: Andrew Thompson | last post by:
- NN 4.78 rendering woes, links at far left - I am trying to rework an old site, make it valid html and css, improving the x-browser and 'older browser' compatibility. My efforts so far, have...
0
by: Arun Bhalla | last post by:
I'm having some inconsistency problems with my deployment project ("Setup") and its custom actions ("Installer"). I'm using Visual Studio .NET 2003 (.NET 1.1, no service pack) on Windows XPSP1. ...
9
by: Mark Rae | last post by:
Hi, This time, I'm looking for a regular expression which says "the string must contain exactly seven or exactly eight digits" e.g. 123456 fails 1234567 passes 12345678 passes 123456789...
1
by: hdogg | last post by:
Scope Woes - IF statement nested in WHILE statement -PHP I have an array $actuals_sum. <?php while(conditions) { if($i == '24) {
4
by: =?Utf-8?B?VkIgSm9ubmll?= | last post by:
I am at my witless end here, please help! I have an ASP.Net aspx web page, hosted on Windows Server 2003, that receives a query string with the path to an autocad drawing file selected from a...
1
by: saddist | last post by:
Hello! I have this code: Const adOpenStatic = 3 Const adLockOptimistic = 3 Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset") ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.