Solved

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

Posted on 2009-06-29
3
801 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

737 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