OracleConnections 是否超时?如果没有,为什么我的 Oracle 会话(在 v$session 中)消失了?

发布于 2024-10-18 23:30:38 字数 1058 浏览 4 评论 0原文

我有一个 WinForms 应用程序,当它第一次启动时,首先创建一个 OracleConnection,然后调用一个将记录写入 user_session 表的存储过程。 OracleConnection 是一个类的静态成员,故意从不释放它,因为我们希望连接在应用程序的生命周期中存在。从本质上讲,这个想法是跟踪谁在任何时候使用该应用程序。当应用程序关闭时,它会调用另一个存储过程从 user_session 表中删除记录。

这一切都运行得很好,但我们想满足应用程序崩溃时罕见的(?)情况,并且 user_session 表中的记录没有被清除。为此,我们有另一个存储过程来检查 Oracle v$session 视图中存在哪些会话,如果它在 user_session 中发现 v$session 中不存在的会话,则会清除 user_session 中的记录。这似乎也很有效。

但现在,我们有了一个新的 WCF 服务,托管在 IIS 6 中。它还执行与 WinForms 应用程序相同的启动逻辑 - 它创建 OracleConnection,并且在服务关闭之前不会释放它。

然而由于某种原因,该服务在 v$session 中的记录正在消失。这种情况发生相当随机,但非常有规律(通常在服务运行几个小时后)。这会导致我们的存储过程在不应该的情况下从 user_sessions 表中清除服务的会话,我正在尝试修复此问题。

那么,关于我的问题:OracleConnections 最终是否会超时,也许它们闲置时间太长?如果是这样,这个超时在哪里配置?如果不是,为什么我的会话会从 v$session 中删除?

我曾想过,如果 OracleConnection 没有被释放,那么会话(在 v$session 中)将无限期地挂起(或者直到进程关闭)下来/杀死)。这似乎就是 WinForms 应用程序中的工作方式。但这并不是我们在 WCF 服务中的经验:正如我所解释的,尽管 OracleConnection 仍然打开,会话还是消失了。 (我尝试监听 StateChange 事件,以防由于某种原因 OracleConnection 被关闭,但该事件从未触发,因此连接肯定仍处于打开状态。我们还将 IIS 配置为不终止空闲进程,因此它是不像服务在我们不知情的情况下被关闭。)

提前致谢。

I have a WinForms app which, when it first starts up, firstly creates an OracleConnection, and then calls a stored procedure that writes a record to a user_session table. The OracleConnection is a static member of a class that is deliberately never disposed, as we want the connection to exist for the lifetime of the app. The idea, essentially, is to keep track of who is using the app at any one time. When the app shuts down, it calls another stored procedure to delete the record from the user_session table.

This all works well enough, but we wanted to cater for the rare (?) occasion when the app crashes, and the record in our user_session table doesn't get cleared. To do this, we have another stored procedure that checks what sessions exist in the Oracle v$session view, and if it finds a session in user_session that doesn't exist in v$session, it cleans up the record in user_session. This also seems to work pretty well.

But now, we have a new WCF service, hosted in IIS 6. It also does the same start-up logic as the WinForms app - it creates the OracleConnection and doesn't dispose of it until the service shuts down.

Yet for some reason, this service's record in v$session is disappearing. This happens fairly randomly, but quite regularly (usually after a few hours of the service running). This causes our stored procedure to clear the service's session from our user_sessions table when it shouldn't, which I'm trying to fix.

So, on to my question: Do OracleConnections eventually time out, perhaps if they are idle for too long? If so, where is this time out configured? If not, why would my session get removed from v$session?

I had thought that if the OracleConnection is not disposed of, then the session (in v$session) would hang around indefinitely (or until the process is shut down/killed). And that seems to be how things work in the WinForms app. But this hasn't been our experience in the WCF service: as I've explained, the session just disappears, despite the OracleConnection still being open. (I've tried listening to the StateChange event, in case for some reason the OracleConnection was being closed, but the event never fires, so the connection is definitely still open. We've also configured IIS to not terminate idle processes, so it's not like the service is being shut down without our knowledge.)

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奈何桥上唱咆哮 2024-10-25 23:30:38

如果您提到您使用的 oracle rdbms 版本,它会有所帮助....
此外,网络状况也会产生影响。是否使用防火墙?

空闲连接被清理的原因有多种:

  1. 防火墙
  2. 用户配置
  3. 文件 资源管理器 空闲超时

2 和 3 默认情况下未启用。如果是这样,请相应地更改它。

对于1,您首先必须知道防火墙是否到位。如果是这样,您可以启用死客户端检测。这应该在服务器上完成,并定期 ping 客户端以查看它是否仍然存在。

我希望这有帮助,
罗纳德

It helps if you mention the oracle rdbms release that you use ....
Also, the network situation can have an effect. Are firewalls in use?

There are several reasons why an idle connection could get cleaned up:

  1. a firewall
  2. a user profile
  3. a resource manager idle timeout

2 and 3 are not enabled by default. If so, change it accordingly.

For 1, you first have to know if a firewall is in place. If so, you could enable Dead Client Detection. This should be done on the server and it regularly pings to the client to see if it is still present.

I hope this helps,
Ronald

风柔一江水 2024-10-25 23:30:38

检查您的防火墙,它可能会在几个小时后终止会话。您也可以设置 SQLNET.EXPIRE_TIME 参数。这可能有助于保持会议的开放。将其设置为几分钟。我猜.NET 使用 NET8 客户端......

Check your firewall, it may be killing sessions after a few hours. You can, alternatively set SQLNET.EXPIRE_TIME parameter. It may help in keeping the session open. Set it to a few minutes. I'm guessing .NET uses a NET8 client...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文