强制关闭在C#中的Oracle连接 [英] Force closing an oracle connection in C#

查看:1048
本文介绍了强制关闭在C#中的Oracle连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个报告窗口其中显示了从一个潜在的长期运行的Oracle存储过程返回的结果。当用户关闭Oracle的连接保持开放和潜在的长期运行报告并没有被取消的窗口我的问题是。

I have a report window which shows the results returned from a potentially long running oracle stored procedure. My problem is when the user closes the window the connection to oracle remains open and the potentially long running report doesn't get cancelled.

关闭打开的连接的唯一方法对于两种数据库管理员手动或用户退出整个应用程序杀死他们。

The only way to close the open connection is for either the DBAs to kill them manually or for the user to exit the entire application.

我已经打过电话关闭来自不同的线程的连接,但这似乎阻挡不断。我也尝试回滚事务,但这表现出同样的问题。

I've tried calling Close on the connection from a different thread, but this seems to continuously block. I also tried rolling back a transaction, but this exhibits the same problem.

我担心,唯一的解决办法将是运行在不同的进程查询(或也许应用程序域?)。

I'm worried that the only solution will be to run the query in a different process (or maybe app domain?).

这可能是因为我缺少明显的东西,任何帮助将不胜感激。

It's likely that I'm missing something obvious, any help would be greatly appreciated.

请仔细阅读

这问题不是包装我在使用语句。它是关于如何的强制正在执行的查询Oracle连接关闭

This question is not about wrapping my connection in a using statement. It is about how to force an oracle connection that is executing a query to close.

例如:


  • 启动一个线程运行查询

  • 藏匿连接对象的地方

  • 呼叫关闭连接对象

  • Start a thread running a query
  • Stash the connection object somewhere
  • Call close on the connection object

public void Go()
{
    OracleConnection connection;
    var queryThread = new Thread(
        () =>
            {
                using (connection = OpenOracleConnection())
                {
                    // execute stored proc that takes 45 mins
                    // raise an event with the data set we load
                }
            });

    Thread.Sleep(3000); // give it time to be useless

    var closeThread = new Thread(
        () =>
            {
                connection.Close();
            });
    closeThread.Start();
}


问题在于这并不关闭连接,而是调用connection.close()时等待执行的程序块。

The problem is that this doesn't close the connection, instead the call to connection.Close() blocks waiting for the procedure to execute.

推荐答案

嗯,我看不到中止/取消正在进行的查询API中的任何东西。技术上讲,它应该是可能的,具有完全权限的第二次会议,以确定要中止,并出具了该届会议杀命令会话。 。我希望你原来的会议,具有某种异常摆脱困境,但我从来没有尝试过了。

Hm, I can't see anything in the API to abort / cancel an ongoing query . Technically it should be possible, with a second session with full privileges, to identify the session you want to abort and issue the kill session command on that session. I would expect your original session to bail out with some kind of exception, but I've never tried it out.

这里的阐述了如何杀死一个会话。

Here it is explained how to kill a session.

< A HREF =http://www.dba-oracle.com/t_how_to_display_session_id_sid.htm相对=nofollow>这里的是回答如何得到会话ID。你会发现,一出开始的长时间运行的查询,那么它应该是很容易杀死正是从第二个连接该会话之前。

Here it is answered how to get the session id. You could find that one out before starting the long running query, then it should be pretty easy to kill exactly that session from a second connection.

让我们知道,如果它的工作原理;)

Let us know if it works ;)

这篇关于强制关闭在C#中的Oracle连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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