我应该在数据库连接字符串中设置最大池大小吗?如果我不这样做会怎样?

问题描述 投票:58回答:3

这是我的数据库连接字符串。直到现在我都没有设置最大池大小。

public static string srConnectionString = 
                       "server=localhost;database=mydb;uid=sa;pwd=mypw;";

因此,我的应用程序当前支持多少个连接?增加连接池大小的正确语法是什么?

该应用程序是用C#4.0编写的。

sql sql-server-2008 connection-string connection-pooling
3个回答
79
投票

当前,您的应用程序支持池中的100个连接。如果要将其增加到200,则conn字符串将如下所示:

public static string srConnectionString = 
                "server=localhost;database=mydb;uid=sa;pwd=mypw;Max Pool Size=200;";

您可以通过在数据库中执行sp_who过程来调查应用程序使用了多少个数据库连接。在大多数情况下,默认的连接池大小将足够。


11
投票

“目前是,但是我认为这可能会在高峰时段引起问题”我可以确认,由于高峰请求,我遇到了超时问题。设置最大池大小后,应用程序运行没有任何问题。IIS 7.5 / ASP.Net


0
投票

我们可以通过以下方式定义最大池大小:

                <pool> 
               <min-pool-size>5</min-pool-size>
                <max-pool-size>200</max-pool-size>
                <prefill>true</prefill>
                <use-strict-min>true</use-strict-min>
                <flush-strategy>IdleConnections</flush-strategy>
                </pool>
© www.soinside.com 2019 - 2024. All rights reserved.