微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 数据库连接池如何影响性能?

我正在使用.Net 2.0 sql Server 2005 Enterprise VSTS 2008 C#ADO.Net来开发ASP.Net Web应用程序. ASP.Net Web应用程序以数据库为中心/驱动.我想知道在ADO.Net连接字符串设置中打开/关闭线程池设置时是否有任何关于性能差异的性能参考数据?性能我的意思是可以支持的并发连接和从ADO.Net客户端执行的特定sql命令的执行时间?

谢谢avdance,
乔治

解决方法

我手边没有任何性能统计数据,但在使用连接池时可能会发出警告:最终可能会出现太多小池,而不是一个大池.

ADO.NET将为其创建一个新的连接池

>每个连接字符串;它对此非常挑剔 – 如果你有两个连接字符串,即使只是一个空格或其他东西也是不同的,那些被认为是两个独立的连接字符串,并将导致创建单独的连接池
>如果使用“集成安全性”(可信连接)设置,则为每个Windows凭据

所以如果你有一个类似的连接字符串

server=MyDBServer;database=MyDatabase;integrated security=sspI;

将创建一个用于每个可区分用户的连接池 – 这是相当反直觉的,但这就是它的方式(并且它不能被影响/关闭).

有关详细信息,请查看ADO.NET连接池上的MSDN docs

When a connection is first opened,a
connection pool is created based on an
exact matching algorithm that
associates the pool with the
connection string in the connection.
Each connection pool is associated
with a distinct connection string.
When a new connection is opened,if
the connection string is not an exact
match to an existing pool,a new pool
is created. 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.

此外,如果您有这两个连接字符串:

server=MyDBServer;database=MyDatabase;user id=tom;pwd=top$secret

server=MyDBServer;database=MyDatabase;user id=tom; pwd=top$secret;

那些被认为是不同的连接字符串,因此将创建两个单独的连接池.

在尝试测量连接池的效果时,需要注意这一点!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐