Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can I issue an OdbcCommand.ExecuteNonQuery() with a timeout

Posted on 2009-06-29
3
Medium Priority
?
844 Views
Last Modified: 2013-12-17
I have a program that writes rows to a table in a database. When a row is written to the table on the database side a trigger is fired. After the trigger successfully completes, the database returns to me a value for the number of rows affected. 1 out of every 10,000 times something goes wrong and the trigger never completes so my program is left in a constant wait state. I was wondering if there is anyway to issue the ExecuteNonQuery() with a timeout that if it doesn't complete successfully in that time I can just reissue the query
Here is my current code:
 using (OdbcCommand odbcCommand = new OdbcCommand("INSERT INTO..."))
{
     odbcCommand.Connection = _odbc;
     //program will wait at this next line indefinitely 
     rowsAffected = odbcCommand.ExecuteNonQuery();
}

Open in new window

0
Comment
Question by:SSAFECS
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
wht1986 earned 2000 total points
ID: 24735657
You should just be able to set the command timeout property
odbcCommand. CommandTimeout = 120; // wait for 2 minutes
rowsAffected = odbcCommand.ExecuteNonQuery();
0
 

Author Comment

by:SSAFECS
ID: 24735692
What happens when the timeout is reached? Does it throw an exception?
0
 
LVL 12

Expert Comment

by:wht1986
ID: 24737920
It should raise a SqlException.  The only 2 times I believe CommandTimeout is ignored is (1) when doing a select (fill) ir if (2) a context connection is being made to the database
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

971 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