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.InvalidO perationExcepti on: 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.ExecuteNonQ uery();
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. 4 3059
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.c om> wrote in message
news:xM******** **********@twis ter01.bloor.is. net.cable.roger s.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.InvalidO perationExcepti on: 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.ExecuteNonQ uery(); 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.
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******** *****@TK2MSFTNG P11.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.c om> wrote in message news:xM******** **********@twis ter01.bloor.is. net.cable.roger s.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.InvalidO perationExcepti on: 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.ExecuteNonQ uery(); 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.
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.c om> wrote in message
news:xU******** ********@news04 .bloor.is.net.c able.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******** *****@TK2MSFTNG P11.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.c om> wrote in message news:xM******** **********@twis ter01.bloor.is. net.cable.roger s.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.InvalidO perationExcepti on: 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.ExecuteNonQ uery(); 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.
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.c om> wrote in message
news:xU******** ********@news04 .bloor.is.net.c able.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******** *****@TK2MSFTNG P11.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.c om> wrote in message news:xM******** **********@twis ter01.bloor.is. net.cable.roger s.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.InvalidO perationExcepti on: 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.ExecuteNonQ uery(); 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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 there's the place where I declare one public static DataReader, but I'm
not sure this is the best way to do it. I use that DataReader in all the
webforms and user controls, whenever I have to read data from the db.
So, should I do it this way or...
|
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 about it and realise that you can only have one DataReader
open on a Connection at a time, but don't know how to rewrite my code to work
properly.
|
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 etc.
This works well, but every now and then a bunch of errors occurs,
relating to either the connection not being initialized, or reader
already associated with existing connection.
Now I have done everything I could think of to get rid of...
|
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 get the error "There is already an open
DataReader associated with this Connection which must be closed first."
How can I fix this error ?
For each DataReader, do I want to open and close the connection (in this
case adoCon) to avoid this error ?...
|
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 reader
and the command object (but don't close the connection which is public in
the solution).
The first time i open my form from a parent form, there is no problem.
Everything works fine. I then close down my form, and I dispose of the form.
| |
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() and
then I execute the command, but I get the following exception message:
" There is already an open DataReader associated with this Command which
must be closed first. "
Searching on google I've found I've to create another connection, but...
|
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 Connection string.
The reason that table adapters are in cache is because I would like to
maintain the connection string that will not be closed for any Insert or
Update as there are thousands of requests per minutes to the WS.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
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...
| |