.Net 允许连接池基于我所阅读的内容,只需将参数添加到 App.config
问题是,我是否应该在我的代码中做任何事情来使用连接池?
在我的代码中,每次需要数据时我都会打开一个连接,并在完成后立即关闭它。我是否应该做一些特殊的事情来重用连接?
最佳答案
只要您的连接使用相同的连接字符串,您就不需要做任何特殊的事情。使用连接,关闭它会自动返回到池中。
来自 SQL Server connection pooling :
Connections are pooled per process, per application domain, per connection string and when integrated security is used, per Windows identity. Connection strings must also be an exact match; keywords supplied in a different order for the same connection will be pooled separately.
您可以在 connection string 本身中配置某些与池相关的选项:
关于.net - Ado.Net - 如何使用连接池?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7543176/