Solved

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

Posted on 2009-06-29
3
811 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
wht1986 earned 500 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

636 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