473,396 Members | 1,966 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,396 software developers and data experts.

sql reader error

Hello,
I am using a reader in order to read query results:

SqlDataReader rdr = null;
SqlDataReader rdr_rows=null;

this.conn.Open();

SqlCommand cmd = new SqlCommand("select name from sysobjects where name
like '%prog%'", this.conn);

rdr = cmd.ExecuteReader();

while (rdr.Read())
{
//some code here
}
if (rdr != null)
{
rdr.Close();
}

foreach (Dbdb data in db_coll)
{
SqlCommand cmd_rows = new SqlCommand("SELECT rows FROM sysindexes WHERE
id = OBJECT_ID('"+db_data.Name+"') AND indid < 2", this.conn);
rdr_rows = cmd_rows.ExecuteReader();
rdr_rows.Read();
System.Console.WriteLine(rdr_rows[0]);
}

I get this error:
There is already an open DataReader associated with this connection
which must be closed first.

Why? I am closing it,how to solve this?
Thanks a lot!



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
1 1352
> SqlDataReader rdr = null;
SqlDataReader rdr_rows=null; Do you get the error here? -> this.conn.Open();
Even so, you tried to open a connection that is already open. If it's open
then just use it; don't try to reopen it.

--
in**@dowhileloop.com
http://dowhileloop.com website development
http://publicjoe.dowhileloop.com -- C# Tutorials

"juli jul" <ju******@yahoo.com> wrote in message
news:e$**************@TK2MSFTNGP14.phx.gbl... Hello,
I am using a reader in order to read query results:
SqlCommand cmd = new SqlCommand("select name from sysobjects where name
like '%prog%'", this.conn);

rdr = cmd.ExecuteReader();

while (rdr.Read())
{
//some code here
}
if (rdr != null)
{
rdr.Close();
}

foreach (Dbdb data in db_coll)
{
SqlCommand cmd_rows = new SqlCommand("SELECT rows FROM sysindexes WHERE
id = OBJECT_ID('"+db_data.Name+"') AND indid < 2", this.conn);
rdr_rows = cmd_rows.ExecuteReader();
rdr_rows.Read();
System.Console.WriteLine(rdr_rows[0]);
}

I get this error:
There is already an open DataReader associated with this connection
which must be closed first.

Why? I am closing it,how to solve this?
Thanks a lot!



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2

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

Similar topics

1
by: Stephen | last post by:
I'm having terrible trouble working out where I have gone wrong in my code below. In the data layer I have two methods and i'm basically returning a command and using it and then returning a...
8
by: Stephan | last post by:
I'm fairly new to python and am working on parsing some delimited text files. I noticed that there's a nice CSV reading/writing module included in the libraries. My data files however, are odd...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
8
by: Todd Bright | last post by:
Is there a way to get the current XmlNode from the reader while in the validation event handler? What I'd like to do is display the error message along with the name of its parent node. In my...
1
by: Stephen | last post by:
I'm having terrible trouble working out where I have gone wrong in my code below. In the data layer I have two methods and i'm basically returning a command and using it and then returning a...
1
by: Aaron | last post by:
I asked for a script that can read info inside a specific xml tag and someone gave me this example. XmlReader reader = new XmlTextReader( filename ); while ( reader.Read() ) { if (...
2
by: Patrick Olurotimi Ige | last post by:
Why do i get "Invalid attempt to FieldCount when reader is closed" Is the problem the way the datareader reads data as opposed to a dataset? When trying to compile this code:- Dim reader As...
5
by: CDMAPoster | last post by:
I have changed how I get the shell path for Acrobat Reader based on code posted by John deKrafft. Does anyone see any problems with this code running on various Windows OS's? '--Begin Module...
6
by: dgleeson3 | last post by:
Hello All I have VB code (.Net 2005) reading from an SQL server 2005 database. Im getting InvalidCastException when doing reader.GetInt32(0) Im simply reading an int from a simple database. It...
0
by: ashes | last post by:
Hi, i created a register form on a website. The information from the form has to go in the customer table in a database in MS Access. the information is going into the table perfectly. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.