加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle – 如何清除ODP.NET连接池中的连接错误?

发布时间:2020-12-12 15:13:58 所属栏目:百科 来源:网络整理
导读:我使用NHibernate和ODP.NET连接到Oracle 11g数据库.当然可以有连接错误(网络故障,DB下降,…).我正在处理我的代码中的所有这些异常,所以没有问题.但是当然用户可以重试他的动作(也许这只是一个短暂的网络故障),而且我的问题是: ODP.NET默认使用连接池.通常没
我使用NHibernate和ODP.NET连接到Oracle 11g数据库.当然可以有连接错误(网络故障,DB下降,…).我正在处理我的代码中的所有这些异常,所以没有问题.但是当然用户可以重试他的动作(也许这只是一个短暂的网络故障),而且我的问题是:

ODP.NET默认使用连接池.通常没有问题,但是当用户在连接错误后重试操作时,NHibernate从ODP.NET获取无效(池化)连接.用户必须重试多次(直到池为空)才能再次工作.

当然我可以禁用ODP.NET中的连接池,但是我想避免这种情况.我还读了一个设置,检查从池中每个返回的连接到DB的连接,但这又增加了我想避免的每个连接的一次往返.

有没有办法配置ODP.NET在任何连接引发连接异常时自动清除连接池?

如果可以使用odac(odp)11g,则可以为池设置验证连接.在使用连接之前,可以验证连接.

The Validate Connection attribute validates connections coming out of the pool. This attribute should be used only when absolutely necessary,because it causes a round-trip to the database to validate each connection immediately before it is provided to the application. If invalid connections are uncommon,developers can create their own event handler to retrieve and validate a new connection,rather than using the Validate Connection attribute. This generally provides better performance.

如果它不够好 – 你可以尝试从oracle的this文档.

Connection Pool Management

ODP.NET connection pool management provides explicit connection pool
control to ODP.NET applications. Applications can explicitly clear
connections in a connection pool.

Using connection pool management,applications can do the following:

Note: These APIs are not supported in a .NET stored procedure. Clear
connections from connection pools using the ClearPool method.

Clear connections in all the connection pools in an application
domain,using the ClearAllPools method.

When connections are cleared from a pool,ODP.NET repopulates the pool
with new connections that have at least the number of connections set
by Min Pool Size in the connection string. New connections do not
necessarily mean the pool will have valid connections. For example,if
the database server is down when ClearPool or ClearAllPools is called,
ODP.NET creates new connections,but these connections are still
invalid because they cannot connect to the database,even if the
database comes up a later time.

It is recommended that ClearPool and ClearAllPools not be called until
the application can create valid connections back to the database.
.NET developers can develop code that continuously checks whether or
not a valid database connection can be created and calls ClearPool or
ClearAllPools once this is true.

另外,可能是this post会帮你的.

更新:
正如@MPelletier所指出的那样,对于oracle 12 the link is different.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读