Click here to Skip to main content
15,923,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wonder if this is possible.
I have a table which contains hundreds of thousands of data.
And as you've already figured out,
having a select statement with a bunch of wheres will still give me the results in at least 4 minutes, causing me to get a timeout error on my .net screen.

I would like to know if it's possible to set a time, say 10 seconds.
And then the query will automatically stop in 10 seconds and give me all the results that have been retrieved only from the first second to the tenth second.
It's not necessary if it find ALL the data. Just SOME will do.

Thanks.
Posted
Updated 13-Mar-12 21:35pm
v2

1 solution

You should select the needed number of rows by setting ROWCOUNT or TOP in the select statement if 'just SOME will do' and you should be looking at fine tuning the query and database for faster results.

.net provides an option to cancel running queries, you will have to add a timer in the code and after the set timeout is reached call the SqlCommand.Cancel method. You can find the details and an example at http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.cancel.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900