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;

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

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

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...