关闭或不关闭 Oracle 连接? [英] To close or not to close an Oracle Connection?

查看:67
本文介绍了关闭或不关闭 Oracle 连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有性能问题,所以我开始从根本上调查这个问题:与数据库的连接".

My application have performance issues, so i started to investigate this from the root: "The connection with the database".

最佳实践说:打开连接,使用它并尽快关闭",但我不知道这会导致开销,所以问题是:

The best practices says: "Open a connection, use it and close is as soon as possible", but i dont know the overhead that this causes, so the question is:

1 -尽快打开、使用、关闭连接是使用 ODP.NET 的最佳方法吗?"

1 -"Open, Use, Close connections as soon as possible is the best aproach using ODP.NET?"

2 - 有没有办法以及如何在 ODP.NET 中使用连接池?我正在考虑创建一个列表来存储一些连接字符串并创建一个逻辑以在每次需要时选择最佳"连接.这是最好的方法吗?

2 - Is there a way and how to use connection pooling with ODP.NET? I thinking about to create a List to store some connections strings and create a logic to choose the "best" connection every time i need. Is this the best way to do it?

推荐答案

这是一个包含 Oracle 推荐的最佳实践的幻灯片:

Here is a slide deck containing Oracle's recommended best practices:

http://www.oracle.com/technetwork/topics/dotnet/ow2011-bp-performance-deploy-dotnet-518050.pdf

您在创建 OracleConnection 时会自动获得一个连接池.对于大多数中间层应用程序,您将希望利用这一点.您还需要通过在注册表中打开性能计数器来调整池以适应实际工作负载.

You automatically get a connection pool when you create an OracleConnection. For most middle tier applications you will want to take advantage of that. You will also want to tune your pool for a realistic workload by turning on Performance Counters in the registry.

有关连接池的详细信息,请参阅 ODP.NET 联机帮助.池设置被添加到连接字符串中.

Please see the ODP.NET online help for details on connection pooling. Pool settings are added to the connection string.

人们在使用 OracleConnections 时经常遇到的另一个问题是垃圾收集器没有意识到它们是真正的资源密集型,也没有及时清理它们.由于 ODP.NET 没有完全托管,因此一些资源对垃圾收集器隐藏,这使情况更加复杂.因此,最佳做法是 Close() AND Dispose() 所有 Oracle ODP.NET 对象(包括 OracleConnection)以强制清理它们.

Another issue people run into a lot with OracleConnections is that the garbage collector does not realize how truly resource intensive they are and does not clean them up promptly. This is compounded by the fact that ODP.NET is not fully managed and so some resources are hidden from the garbage collector. Hence the best practice is to Close() AND Dispose() all Oracle ODP.NET objects (including OracleConnection) to force them to be cleaned up.

Oracle 完全托管的提供程序将缓解这一特殊问题(很快就会推出测试版)

This particular issue will be mitigated in Oracle's fully managed provider (a beta will be out shortly)

(ODP.NET,托管驱动程序现已可用.)

( ODP.NET, Managed Driver is now available.)

克里斯蒂安·谢伊

甲骨文

这篇关于关闭或不关闭 Oracle 连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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