473,769 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IDataReader closed on return from proc

Whenever I try the following, the reader that is returned is always
closed. What am I missing ?

When I look at the reader in the ExecuteReader, it is fine. THen it
gets closed on the returm.
Thanks!
=============== =============
public void Test()
{
IDBGateway gateway = new
DBGateway(Conne ctionChoice.DOM );
using (IDataReader reader =
gateway.Execute Reader( Utility.GroupSq l,null))
{
while (reader.Read())
{
Debug.WriteLine (reader[0].ToString());
}
}
}
=============== ====
Gateway code: ( and all of the factory stuff is fine )
public IDataReader ExecuteReader(s tring selectStatement ,
IDataParameterC ollection parameters)
{
try
{
using (IDbConnection connection =
factory.CreateC onnection())
{
IDbCommand command = connection.Crea teCommand();
command.Command Text = selectStatement ;
command.Command Type = CommandType.Tex t;
try
{
connection.Open ();
}
catch
{
throw;
}
IDataReader reader =
command.Execute Reader( CommandBehavior .CloseConnectio n);
return reader;
}
}
catch
{
throw;
}
}

Jun 22 '07 #1
2 2088
* Larry R wrote, On 22-6-2007 18:56:
Whenever I try the following, the reader that is returned is always
closed. What am I missing ?

When I look at the reader in the ExecuteReader, it is fine. THen it
gets closed on the returm.
The using clause around your connection will close the connection as
soon as that code block is left. It will close the reader with it.

There is a property you can set on the reader to close the connection
when the reader itself is being disposed. Which you are already setting.
So not disposing the connection immediately should solve your issue.

Jesse Houwing

Updated code:

public void Test()
{
IDBGateway gateway = new
DBGateway(Conne ctionChoice.DOM );
using (IDataReader reader =
gateway.Execute Reader( Utility.GroupSq l,null))
{
while (reader.Read())
{
Debug.WriteLine (reader[0].ToString());
}
}
}
=============== ====
Gateway code: ( and all of the factory stuff is fine )
public IDataReader ExecuteReader(s tring selectStatement ,
IDataParameterC ollection parameters)
{
IDbConnection connection;
try
{
connection = factory.CreateC onnection()
{
IDbCommand command = connection.Crea teCommand();
command.Command Text = selectStatement ;
command.Command Type = CommandType.Tex t;
try
{
connection.Open ();
}
catch
{
throw;
}

IDataReader reader =
command.Execute Reader( CommandBehavior .CloseConnectio n);
return reader;
}
}
catch
{
if (connection != null)
{
connection.Disp ose();
}
throw;
}
}
Jun 22 '07 #2
Thanks so much!

Jun 23 '07 #3

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

Similar topics

1
3150
by: Robin Hammond | last post by:
Can anybody tell me why a) when running a stored proc from an asp page to return a recordset the command succeeds if the sp queries an existing table directly, but b) if the stored proc populates results into a different table, temporary table, global temp table, or table variable, then queries one of these, the asp page reports that the recordset object is closed. If using a table, I have set grant, select, update, delete permissions for...
5
1979
by: Tamir Khason | last post by:
As far as I understand, IDataReader, based on command recieves isClosed property when the connection closes. How to prevent it?
5
7038
by: Gelios | last post by:
Hello All! I am going to crazy and feeling myself so stupid but I don't understand such behaviour. I have code: public int getNextAgentId() { Int32 agent_id = 0; IDataReader dr = dbap.DBDataReader("SELECT MAX(agent_id) FROM Agents"); if(dr.Read()) { agent_id = dr.GetInt32(0);
10
1688
by: Brent | last post by:
I'm quickly running out of available db connections with the code below. I like to think I'm closing everything as I go along, but I watch the connections shoot up as soon as the the method getIDs comes into play. Does anyone see anything obvious? It's almost as if my code can't close a DB connection as fast as it can open it... Thanks for any help! --Brent
3
2367
by: js | last post by:
Hi, I want to debug the return idatareader, how to print out some fields value? many thanks.
2
1566
by: יוני גולדברג | last post by:
Hi, In few places within my code the business object pass IDataReader to the GUI. Suddenly i noticed that nowhere in the code the IDataReader is being closed. Does the data binding operation closes the IDataReader? If i didn't close it explicitly, the IDataReader remains open untill GC will clean it?
0
1315
by: rsdev | last post by:
Hi, I am new to ASP.NET and I am trying to build a CMS application using theBeerHouse SK. I am adapting the Datareader to collect information from an SQL database and send it to an HtmlHeader. Using N-Tier architecture I keep recieving an object reference required error. Here's my code: Home.aspx.cs
2
2868
by: RP | last post by:
I saw a code in a class where IDataReader is used to retrieve result from query, even if only one column is to be retrieved. It uses a CommandObject with ExecuteReader but not using ExecuteScalar. For what IDataReader is used and what are the benefits of it as compared to sime DataReader.
0
1164
by: Kevac Marko | last post by:
Hi. I have to send UDP packets very often. Approx twice in a second. But socket is not closed after sending packet. So soon i bump into open sockets\files limit. How to close socket after sending data? Python 2.5, Twisted class DataClient(DatagramProtocol):
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10208
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.