我们能否取消查询颁发给SQL Server? [英] Can we cancel query issued to sql server?
问题描述
我有一个复杂的SQL语句,它涉及到很多我想知道是否有可能取消颁发给SQL服务器,查询计算等?
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?
例。有一个叫搜索和用户点击搜索按钮。我想显示一个名为取消按钮,并应取消颁发给SQL服务器的查询。
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.
这可能吗?
推荐答案
有很多在ADO.NET asynchron功能,例如<一href="http://msdn.microsoft.com/en-us/library/ca56w9se%28v=vs.100%29.aspx"><$c$c>SqlCommand.BeginExecuteNonQuery$c$c>.
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.
所以伪code,你可以做以下步骤:
So in pseudo-code you can do these steps:
- 在用户点击<大骨节病>搜索骨节病>按钮。
- 在按钮的处理程序,打开你的数据库连接等。
- 显示你的<大骨节病>取消骨节病>按钮。
- 打电话给你选择的ADO.NET异步功能。
- 存储
的IAsyncResult
返回函数调用的对象(当操作完成后,再次隐藏取消按钮检测)。 - 在取消按钮的处理程序,调用<一href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.cancel%28v=vs.100%29.aspx"><$c$c>Cancel$c$c>法
的SqlCommand
。
- User clicks the Search button.
- In the button's handler, open your DB connection and the like.
- Show your Cancel button.
- Call the ADO.NET async function of your choice.
- Store the
IAsyncResult
returned object of the function call (for detecting when the operation has finished to hide the cancel button again). - In the cancel button's handler, call the
Cancel
method ofSqlCommand
.
这篇关于我们能否取消查询颁发给SQL Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!