我们能否取消查询颁发给SQL Server? [英] Can we cancel query issued to sql server?

查看:161
本文介绍了我们能否取消查询颁发给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.

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:

  1. 在用户点击<大骨节病>搜索按钮。
  2. 在按钮的处理程序,打开你的数据库连接等。
  3. 显示你的<大骨节病>取消按钮。
  4. 打电话给你选择的ADO.NET异步功能。
  5. 存储的IAsyncResult 返回函数调用的对象(当操作完成后,再次隐藏取消按钮检测)。
  6. 在取消按钮的处理程序,调用<一href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.cancel%28v=vs.100%29.aspx"><$c$c>Cancel的SqlCommand
  1. User clicks the Search button.
  2. In the button's handler, open your DB connection and the like.
  3. Show your Cancel button.
  4. Call the ADO.NET async function of your choice.
  5. Store the IAsyncResult returned object of the function call (for detecting when the operation has finished to hide the cancel button again).
  6. In the cancel button's handler, call the Cancel method of SqlCommand.

这篇关于我们能否取消查询颁发给SQL Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆