且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是连接池必须具备的ODP.NET?

更新时间:2023-09-21 08:47:58

有关池的唯一原因就是性能,因此,如果您夜间作业它的窗口内运行,没有什么不对的你在做什么,特别是因为它让你实现通过简单不必担心死连接。

不过,我不会让这种标准的做法。我很少写code处理陈旧的连接,即使在当时它是一个简单的工厂。这个问题与你们为什么都失效连接开始?通常,这涉及任一防火墙或DBA工作终止空闲连接,这两者应该改变或松弛为应用程序的帐户。即使在这种情况下,你可以做到以下几点:

  • 在连接字符串中指定最小池大小= 0。这样做可以让ODP.net清理,即使你的应用程序拥有的最后一个连接,让您的应用程序,以完全断开时,它的闲置时间足够长。
  • 指定一个更高的DECR池大小在连接字符串。这将允许更多的空闲连接被ODP.net关闭每隔3分钟。
  • 您可以尝试设置验证连接=真 - 我的猜测是有较少的开销比确认存在与开放的一个连接

更多信息可以在这里找到: http://docs.oracle.com/cd/E15296_01/doc.111/e15167/featConnecting.htm#i1006228

I am writing a nightly job to move data from SQL Server to Oracle using ODP.NET.

We use around 100 connection objects(independent of data) and we don't expect more than 1500 rows to transfer in a single run(in total). The ODP.NET notes and materials I read never talk about keeping connection pooling off.

In dev, I keep the connection pooling off and it just works fine.

Is it advisable in the given scenario to keep the connection pooling off,(given all the connections are disposed properly after use)since:

  1. It is a nightly job and there wont be much load on the Oracle server.

  2. Connection Pooling might return stale connections, for which validate settings/exception handing needs to be done.

The only reason for pooling is performance, so if your nightly job runs within it's window, there's nothing wrong with what you are doing, especially since it keeps your implementation simple by not having to worry about dead connections.

That said, I wouldn't make this standard practice. I rarely write code to handle stale connections and even then it's a simple factory. The question starts with why do you have stale connections at all? Typically this relates to either a firewall or a DBA job terminating idle connections, both of which should be changed or relaxed for an application account. Even in that case you can do the following:

  • Specify Min Pool Size=0 in your connection string. Doing so lets ODP.net clean up even the last connection your app has, allowing your app to completely disconnect when it's idle for a long enough period.
  • Specify a higher Decr Pool Size in your connection string. This will allow for more idle connections to be closed every 3 minutes by ODP.net.
  • You could try setting Validate Connection = true - My guess would be there's less overhead validating the connection than there is with opening one.

More info can be found here: http://docs.oracle.com/cd/E15296_01/doc.111/e15167/featConnecting.htm#i1006228