Reputation: 7547
I have a complex piece of SQL and it involves lot of calculations etc. I want to know whether it is possible to cancel the query that is issued to the SQL server?
Ex. There is a button named Search and user clicks on Search. I want to show a button named "Cancel" and that should cancel the query issued to the SQL server.
Is this possible?
Upvotes: 1
Views: 1070
Reputation: 40736
There are a lot of asynchron functions in ADO.NET, e.g. SqlCommand.BeginExecuteNonQuery
.
You can call these functions in your application, store the result object and cancel it when the user clicks the "Cancel" button.
So in pseudo-code you can do these steps:
IAsyncResult
returned object of the function call (for detecting when the operation has finished to hide the cancel button again).Cancel
method of SqlCommand
.Upvotes: 8