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

DataReader associated with this Connection

Hi everyone,

I am working on the 'Delete' section of my program. What I need to do is
query my database and for every ID that it finds I want to remove a
file+ID.jpg from my file folder and update another table with that
information. However, I'm getting the following error message.

There is already an open DataReader associated with this Connection which
must be closed first.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: There is already an
open DataReader associated with this Connection which must be closed first.

Source Error:
Line 471: SqlParameter BParBID = Cmd.Parameters.Add("@BID",
SqlDbType.Int);
Line 472: BParBID.Value = BID;
Line 473: Cmd.ExecuteNonQuery();
Line 474:
Line 475: DeleteSQL = "DELETE FROM BannerInfo WHERE BID=@BID";

But this doesn't use the DataReader? only my query to find IDs is using the
datareader. Any idea why this is happening? and what would be a work-around
this?

Thank you
Maz.
Nov 18 '05 #1
4 3036
Yes - the message says, there is already an open data reader on the
connection. Meaning, that because there is an open data reader, you cannot
do anything else with the connection until that datareader is closed.

So close your data reader before executing any queries, or create a second
connection.

"Maziar Aflatoun" <ma***@rogers.com> wrote in message
news:xM******************@twister01.bloor.is.net.c able.rogers.com...
Hi everyone,

I am working on the 'Delete' section of my program. What I need to do is
query my database and for every ID that it finds I want to remove a
file+ID.jpg from my file folder and update another table with that
information. However, I'm getting the following error message.

There is already an open DataReader associated with this Connection which
must be closed first.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: There is already an
open DataReader associated with this Connection which must be closed first.
Source Error:
Line 471: SqlParameter BParBID = Cmd.Parameters.Add("@BID",
SqlDbType.Int);
Line 472: BParBID.Value = BID;
Line 473: Cmd.ExecuteNonQuery();
Line 474:
Line 475: DeleteSQL = "DELETE FROM BannerInfo WHERE BID=@BID";

But this doesn't use the DataReader? only my query to find IDs is using the datareader. Any idea why this is happening? and what would be a work-around this?

Thank you
Maz.

Nov 18 '05 #2
I'm under the impression that it's a bad programming practise when you
create multiple connections. Is it?

Thanks
Maz.

"Marina" <so*****@nospam.com> wrote in message
news:e6*************@TK2MSFTNGP11.phx.gbl...
Yes - the message says, there is already an open data reader on the
connection. Meaning, that because there is an open data reader, you cannot
do anything else with the connection until that datareader is closed.

So close your data reader before executing any queries, or create a second
connection.

"Maziar Aflatoun" <ma***@rogers.com> wrote in message
news:xM******************@twister01.bloor.is.net.c able.rogers.com...
Hi everyone,

I am working on the 'Delete' section of my program. What I need to do is
query my database and for every ID that it finds I want to remove a
file+ID.jpg from my file folder and update another table with that
information. However, I'm getting the following error message.

There is already an open DataReader associated with this Connection which
must be closed first.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: There is already an
open DataReader associated with this Connection which must be closed

first.

Source Error:
Line 471: SqlParameter BParBID = Cmd.Parameters.Add("@BID",
SqlDbType.Int);
Line 472: BParBID.Value = BID;
Line 473: Cmd.ExecuteNonQuery();
Line 474:
Line 475: DeleteSQL = "DELETE FROM BannerInfo WHERE BID=@BID";

But this doesn't use the DataReader? only my query to find IDs is using

the
datareader. Any idea why this is happening? and what would be a

work-around
this?

Thank you
Maz.


Nov 18 '05 #3
That depends. If you can get around by using 1, then creating extra ones is
bad - since you are wasting resources for no reason. But if you actually
need 2, then you need 2.

"Maziar Aflatoun" <ma***@rogers.com> wrote in message
news:xU****************@news04.bloor.is.net.cable. rogers.com...
I'm under the impression that it's a bad programming practise when you
create multiple connections. Is it?

Thanks
Maz.

"Marina" <so*****@nospam.com> wrote in message
news:e6*************@TK2MSFTNGP11.phx.gbl...
Yes - the message says, there is already an open data reader on the
connection. Meaning, that because there is an open data reader, you cannot do anything else with the connection until that datareader is closed.

So close your data reader before executing any queries, or create a second connection.

"Maziar Aflatoun" <ma***@rogers.com> wrote in message
news:xM******************@twister01.bloor.is.net.c able.rogers.com...
Hi everyone,

I am working on the 'Delete' section of my program. What I need to do is query my database and for every ID that it finds I want to remove a
file+ID.jpg from my file folder and update another table with that
information. However, I'm getting the following error message.

There is already an open DataReader associated with this Connection which must be closed first.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed

first.

Source Error:
Line 471: SqlParameter BParBID = Cmd.Parameters.Add("@BID",
SqlDbType.Int);
Line 472: BParBID.Value = BID;
Line 473: Cmd.ExecuteNonQuery();
Line 474:
Line 475: DeleteSQL = "DELETE FROM BannerInfo WHERE BID=@BID";

But this doesn't use the DataReader? only my query to find IDs is using

the
datareader. Any idea why this is happening? and what would be a

work-around
this?

Thank you
Maz.



Nov 18 '05 #4
It's a good idea to avoid multiple database connections when you can, but it
may be justified in this case.
Another possible solution is to load your data into a DataSet instead of a
DataReader. Since DataSets are disconnected you won't have this problem.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Maziar Aflatoun" <ma***@rogers.com> wrote in message
news:xU****************@news04.bloor.is.net.cable. rogers.com...
I'm under the impression that it's a bad programming practise when you
create multiple connections. Is it?

Thanks
Maz.

"Marina" <so*****@nospam.com> wrote in message
news:e6*************@TK2MSFTNGP11.phx.gbl...
Yes - the message says, there is already an open data reader on the
connection. Meaning, that because there is an open data reader, you
cannot
do anything else with the connection until that datareader is closed.

So close your data reader before executing any queries, or create a
second
connection.

"Maziar Aflatoun" <ma***@rogers.com> wrote in message
news:xM******************@twister01.bloor.is.net.c able.rogers.com...
Hi everyone,

I am working on the 'Delete' section of my program. What I need to do
is
query my database and for every ID that it finds I want to remove a
file+ID.jpg from my file folder and update another table with that
information. However, I'm getting the following error message.

There is already an open DataReader associated with this Connection
which
must be closed first.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: There is already an
open DataReader associated with this Connection which must be closed

first.

Source Error:
Line 471: SqlParameter BParBID = Cmd.Parameters.Add("@BID",
SqlDbType.Int);
Line 472: BParBID.Value = BID;
Line 473: Cmd.ExecuteNonQuery();
Line 474:
Line 475: DeleteSQL = "DELETE FROM BannerInfo WHERE BID=@BID";

But this doesn't use the DataReader? only my query to find IDs is using

the
datareader. Any idea why this is happening? and what would be a

work-around
this?

Thank you
Maz.



Nov 18 '05 #5

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

Similar topics

2
by: Andrei Pociu | last post by:
In a typical ASP .NET Web Application (website), I'm currently using a class where I declare some public static objects. For example there's the place where I initialize the SqlConnection. Also...
2
by: Grant | last post by:
Hi, I keep getting the following error message: InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first. I have read up...
3
by: Rykie | last post by:
I have an application that constantly needs to read and write data to a SQL box. For most of my read transactions I use a datareader. I compiled a class that has all my datareader commands in it...
20
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I...
3
by: Johnny Jörgensen | last post by:
I've got an error that I simply cannot locate: I've got a form in which I use a datareader object to read information from a db. After the read, I close the reader and I dispose of both the...
3
by: BLUE | last post by:
I've a TransactionScope in which I select some data and I want to do some queries for each record retrieved with my select. I'm using a DataReader and for each record I do factory.CreateCommand()...
11
by: =?Utf-8?B?QXNhZg==?= | last post by:
Hello, I have two Table Adapters that I am storing in a Cache using .NET 2.0 Web Service and the Database is SQL Server on Windows 2003 IIS6. Each of the two table adapters has its own...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.