ODP.NET连接池:如何判断是否已使用连接 [英] ODP.NET connection pooling: How to tell if a connection has been used

查看:117
本文介绍了ODP.NET连接池:如何判断是否已使用连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改Winforms应用程序以使用连接池,以便可以在后台线程中进行数据访问.业务逻辑是在PL/SQL中实现的,为了使用业务逻辑,必须调用几个与安全性相关的存储过程.

我需要一种方法来判断是否已使用该连接而无需往返数据库.我认为我不能在HashSet中跟踪它们,因为我怀疑是否可以依赖Equals甚至ReferenceEquals.有什么想法吗?

请明确一点,我计划使用ODP.NET的内置连接池机制.如果我滚动自己的连接池,那么跟踪哪些连接是新连接还是已使用连接将非常简单.

解决方案

ODP.NET提供的连接池是完全不透明的.也就是说,它不会像我希望的那样泄漏-无法知道连接之前是否已使用过或者是全新的.但是,它是另一种泄漏性的抽象:在连接的使用之间保留任何会话状态(例如,会话范围内的程序包作用域变量).既然这是有关确定连接的使用状态与新状态的问题,而无需进入数据库,那么答案是,使用ODP.NET的内置连接池根本无法完成连接.

留下两个选择:

  1. 创建一个连接池实现,该实现要么提供该信息,要么在创建每个新连接时执行用户定义的初始化;或
  2. 执行往返数据库的操作,以确定连接的使用状态与新状态.

I'm modifying a Winforms app to use connection pooling so data access can occur in background threads. The business logic is implemented in PL/SQL and there are a couple of security related stored procedures that have to be called in order to make use of the business logic.

What I need is a way to tell if the connection has been used without a round-trip to the database. I don't think I can keep track of them in a HashSet because I doubt Equals or even ReferenceEquals could be relied upon. Any ideas?

EDIT:

Just to be clear, I plan to use ODP.NET's built-in connection pooling mechanism. If I rolled my own connection pool, keeping track of which connections were new vs. used would be extremely trivial.

解决方案

The connection pooling provided by ODP.NET is completely opaque. That is, it isn't leaky in the way I'd like it to be - there is no way of knowing if a connection has been used before or is brand new. However it is a leaky abstraction in another way: Any session state (e.g. package scoped variables, which are session scoped) is preserved between usages of the connection. Since this is a question about determining the used vs. new state of a connection without going to the database, the answer is that it simply cannot be done using ODP.NET's built-in connection pool.

That leaves two options:

  1. Create a connection pool implementation that either provides that information or performs user-defined initialisation upon creation of each new connection; or
  2. Perform a round-trip to the database to determine the used vs. new state of the connection.

这篇关于ODP.NET连接池:如何判断是否已使用连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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