sql查询执行终止的问题 [英] issue with sql query execution termination

查看:187
本文介绍了sql查询执行终止的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过点击按钮来停止长时间运行的查询?



要求显示在点击停止按钮之前获取的记录。



示例:



如果我有1000行的表我想通过点击停止按钮来终止中间执行当我点击停止按钮时,当时有500条记录它应该只显示500条记录。



注意:在我的代码中我使用datareader从数据库中获取记录和绑定数据表。



请使用计时器或线程概念建议一种方法。

How to stop long running query by clicking on button?

Requirement is to display records fetched until the stop button is clicked.

example:

if i have table with 1000 rows i want to terminate execution in middle by clicking on stop button if it fetched only 500 records at that time when i click on stop button it should display 500 records only.

Note:in my code i was using datareader to fetch records from database and binding to datatable.

please suggest a way how to do it using timer or threading concept.

推荐答案

您可以使用 SQLCommand.Cancel方法取消查询[ ^ ]但请记住,命令m我将在另一个线程中运行,否则在命令完成后将调用Cancel方法。



另一种方法是指定一个CommandTimeout来取消在指定的时间限制内运行时执行的查询。
You can cancel the query by using SQLCommand.Cancel method[^] But remember, the command must be running in another thread, otherwise Cancel method will be called after the command is finished.

Another method is to specify a CommandTimeout to cancel query executing when it runs over a specified time limit.


这篇关于sql查询执行终止的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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