Ado.Net - 如何使用连接池?如何使用、连接池、Ado、Net

2023-09-05 23:17:57 作者:人不疯狂枉骚年

.NET允许其依据是什么我读过连接池仅仅是通过添加参数的App.config

.Net allows connection pooling which based on what I've read is simply by adding parameters to App.config

现在的问题是,我,我想在我的code使用连接池做什么? 在我的code我打开每一次数据需要有一个连接,我只要我完成关闭它。是我该做什么特别的复用连接?

The question is, am I suppose to do anything in my code to use the connection pool? In my code I open a connection every time data is needed and I close it as soon as I'm done. Am i suppose to do anything special to reuse connections?

推荐答案

您不需要,只要你的连接使用相同的连接字符串做什么特别的事情。使用该连接,将其关闭,并会自动返回到池中。

You don't need to do anything special as long as your connections use the same connection string. Use the connection, close it and will automatically return to the pool.

从 SQL Server连接池:

连接的每个进程池,每个应用程序域,每   连接字符串并在集成的安全性时,每个视窗   身份。连接字符串也必须完全匹配;关键字   以不同的顺序进行相同的连接供给将被汇集   分开。

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字符串本身:

在池(默认启用) 在连接生存期(或负载平衡超时) 在争取 在最大池大小 在小池大小