Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Regular expression help 2 35
VB.Net/LINQ: ".Contains" condition not finding existing result in MSSQL 16 43
Finding the IIS version 5 22
how to just get time from a date 6 34
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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