如何取消长时间运行的数据库操作? [英] How to cancel a long-running Database operation?

查看:230
本文介绍了如何取消长时间运行的数据库操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前使用Oracle,但也需要一个MS SQL解决方案。



我有一个GUI,允许用户生成将在数据库上执行的SQL 。这可能需要很长时间,这取决于他们生成的搜索。我想让GUI /应用程序在此搜索期间响应,我希望用户能够取消搜索。



我使用的是后台工作线程。 p>

我的问题是,当用户取消搜索时,我不能中断对数据库的调用。它等待,直到它完成,然后,它可以轮询CancelationPending属性。



如果用户在很长的查询中点击搜索,然后点击取消 ',然后再次'搜索' - 第一个搜索仍然在数据库上。当他们再次点击搜索时,后台工作人员仍然很忙。我遇到这个问题的唯一解决方案是做一个新的后台工作者。



这似乎是一个真的丑陋的方式来做事情。数据库保持工作我正在创建新的背景工人的实例....当我真的想停止数据库调用并重用同一个工作。



我该如何做?

解决方案

是可能的。这是一个指向Oracle网站上有关此主题的讨论的链接:
http://forums.oracle.com/forums/thread.jspa?threadID=400492&start=15&tstart=0


Currently working with Oracle, but will also need a solution for MS SQL.

I have a GUI that allows users to generate SQL that will be executed on the database. This can take a very long time, depending on the search they generate. I want the GUI/App to responsive during this search and I want the user to be able to cancel the search.

I'm using a Background Worker Thread.

My problem is that, when the user cancels the search, I can't interrupt the call to the database. It waits until it is finished and then, it can poll the 'CancelationPending' property. Not only does this waste resources on the database, but it creates problems for my code.

If the user hits 'Search' on a very long query, then clicks 'Cancel' and then 'Search' again - the first search is still chugging away on the database. The background worker is still busy when they hit search again. The only solution I've got to this problem is to make a new background worker.

It seems like a really ugly way to do things. The database keeps working I'm creating new instances of background workers....when I really want to STOP the database call and re-use the same worker.

How can I do that?

解决方案

I dont think it is possible. Here is a link to a discussion on Oracle's website about this topic: http://forums.oracle.com/forums/thread.jspa?threadID=400492&start=15&tstart=0

这篇关于如何取消长时间运行的数据库操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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