We help IT Professionals succeed at work.

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

SSAFECS
SSAFECS asked
on
Medium Priority
926 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

Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
What happens when the timeout is reached? Does it throw an exception?

Commented:
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
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.