Solved

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

Posted on 2009-06-29
3
765 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 500 total points
Comment Utility
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
Comment Utility
What happens when the timeout is reached? Does it throw an exception?
0
 
LVL 12

Expert Comment

by:wht1986
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

9 Experts available now in Live!

Get 1:1 Help Now