Stop SQL query execution from .net Code

这一生的挚爱 提交于 2019-11-26 07:48:21

问题


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?


回答1:


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




回答2:


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.




回答3:


You can do myCommand.Cancel(), and this will work best as even i have face similar issue in past, and using myCommand.Cancel() i have solved my issue. :) :)



来源:https://stackoverflow.com/questions/4779679/stop-sql-query-execution-from-net-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!