oracle – 如何清除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.

相关文章

Java Oracle 结果集是Java语言中处理数据库查询结果的一种方...
Java AES和Oracle AES是现代加密技术中最常使用的两种AES加密...
Java是一种广泛应用的编程语言,具备可靠性、安全性、跨平台...
随着移动互联网的发展,抽奖活动成为了营销活动中不可或缺的...
Java和Oracle都是在计算机领域应用非常广泛的技术,他们经常...
Java 是一门非常流行的编程语言,它可以运行于各种操作系统上...