Solved

The OleDbCommand is currently busy Open, Fetching

Posted on 2006-07-18
9
761 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

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

Bob
0
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# winforms programmitically move panels 6 53
What Does This C# Code Block Do? 5 72
Can I command line build a C# application? 6 53
VS2010 Build fails to install 14 79
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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