Solved

The OleDbCommand is currently busy Open, Fetching

Posted on 2006-07-18
9
754 Views
Last Modified: 2007-11-27
Hi,

When I perform a query, followed by another query, the OleDbCommand is still busy.  How should I re-initialize this?

Thanks,
Bob

sql = "SELECT * FROM DeliveryRunDetail WHERE ProcessName='Test';
dbCommand1.CommandText = sql;
dbCommand1.ExecuteNonQuery();
                        
reader = dbCommand1.ExecuteReader();      
while ( reader.Read() )
{
    // do something
}                        

sql = "DELETE * FROM DeliveryRunDetail WHERE ProcessName='Test2'";
dbCommand1.CommandText = sql;
dbCommand1.ExecuteNonQuery();
0
Comment
Question by:ba272
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 6

Expert Comment

by:mogun
ID: 17135006
Close Reader before executing other SQL commands using the same command object.

Cheers
Mohan
0
 
LVL 13

Assisted Solution

by:BlackTigerX
BlackTigerX earned 100 total points
ID: 17135320
reader.Close();                    
reader = dbCommand1.ExecuteReader();    
while ( reader.Read() )
{
    // do something
}        
0
 
LVL 6

Assisted Solution

by:mogun
mogun earned 100 total points
ID: 17138329
The correct one is

reader = dbCommand1.ExecuteReader();    
while ( reader.Read() )
{
    // do something
}                    

reader.Close();

sql = "DELETE * FROM DeliveryRunDetail WHERE ProcessName='Test2'";
dbCommand1.CommandText = sql;
dbCommand1.ExecuteNonQuery();
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17141497
Creating a new command instance would be better.

Bob
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ba272
ID: 17142814
Hey Bob,

could you give an example so we're on the same page?

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17142914
Bob,

Do you want to stick with the OleDbDataReader?

Bob
0
 

Author Comment

by:ba272
ID: 17143607
for now.  I've got quite a large program created.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 300 total points
ID: 17151352
Try this, then:

sql = "DELETE * FROM DeliveryRunDetail WHERE ProcessName='Test2' ";
OleDbCommand dbCommand2 = new OleDbCommand(sql, connection);
dbCommand2.ExecuteNonQuery();

Bob
0
 

Author Comment

by:ba272
ID: 17151365
ok
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Definitions and default visual studio colors 5 58
Resolve Dependency Issues 4 47
Angular JS Route 3 52
Wav problem 4 16
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now