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

前端之家收集整理的这篇文章主要介绍了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.

猜你在找的Oracle相关文章