views:

107

answers:

3

Hi folks, i have a sql query with multiple joins & it pulls data from a database for processing. This is supposed to be running on some scheduled basis. So day 1, it might pull 500, day 2 say 400.

Now, if the service is stopped for some reason & the data not processed, then on day3 there could be as much as 1000 records to process. This is causing timeout on the sql query.

How best to handle this situation without causing timeout & gradually reducing workload to process?

TIA

+3  A: 

Look at your query, it could be that its not optimised, put indexes where appropriate. Without seeing your table structure, query, cant help any more.

Jason Jong
Yes. This is the best start- the numbers of the OP indicate heavy brutal work or totally crappy query. A timeout with only 1000 results should not happen.
TomTom
@TomTom: There's no relation between query cost and the number of results. A query with 1000 results can require an arbitrary amount of calculation and/or disk I/O
Andomar
As I said - either brutal work heavy, or bad indices. There IS a statistical relation - 1000 results on average are less reosourcei ntensive than 10.000.000. 1000 results should under most queries come within seconds. Given the small amount of data in the result, pointing to optimization is a valid answer.
TomTom
+3  A: 

create a batch process. Allow no more than say n records to process. Lets say n = 100 ... then make your select queries to only select top 100 until there are no more records to process.

YourCommandObject.CommandTimeout = 0;

This will allow your command to run forever.

Note this could cause database locks and other issues. If you use the batch process I described above and determine the longest running query you can set your connect timeout to what is necessary.

John Hartsock
Connection timeout controls making connections; it doesn't affect how long a query can run before it times out
Andomar
sorry your right I meant to say command timeout...crap and that is in the Command object...man did I mess up
John Hartsock
+1  A: 

One practical solution would be to increase the command timeout:

var com = yourConnection.CreateCommand();
com.CommandTimeout = 0;
...

The CommandTimeout property is the time (in seconds) to wait for the command to execute. The default is 30 seconds. A value of 0 indicates no limit, and should be avoided in a CommandTimeout because an attempt to execute a command will wait indefinitely.

Andomar