Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop SQL query execution from .net Code

I'm executing one stored procedure from the '.net' code. Since there is a lot of data, it is taking too much time to execute. Is there any way to stop this execution from the c# code?

In other words, if we execute the query from database itself, there is a option to stop its execution but in the code is it possible?

like image 281
NaveenBhat Avatar asked Jan 24 '11 07:01

NaveenBhat


People also ask

How do I stop a SQL query from running?

SQL Server Management Studio Activity Monitor Scroll down to the SPID of the process you would like to kill. Right click on that line and select 'Kill Process'. A popup window will open for you to confirm that you want to kill the process.

How do you stop a query in Visual Studio?

To stop a queryRight-click anywhere in the Results pane, on the shortcut menu point to Pane, and then click Clear Results.

How do you stop a query in Toad?

The Cancel Query Execution or Fetch button enables a long-running SQL query to be interrupted and control returned to Toad. To be able to cancel queries, you must select the Execute Queries in Threads option by choosing Main Menu → View → Toad Options → Oracle → Transactions, as shown in Figure 5.14.


2 Answers

Yes sqlcommand.cancel is your friend http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.cancel.aspx

like image 80
stefan Avatar answered Sep 23 '22 04:09

stefan


Yes, you can cancel the query by using SqlCommand.Cancel. However, the command must be running in another thread (otherwise Cancel will be called only after the command is finished).

Also you can specify a CommandTimeout if you want to cancel this query when it runs over a specified time limit.

like image 41
Andrey Shchekin Avatar answered Sep 22 '22 04:09

Andrey Shchekin