SQL 我应该在数据库连接字符串中设置最大池大小吗?如果我不这样做会怎样?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7784100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Should I set max pool size in database connection string? What happens if I don't?
提问by MonsterMMORPG
This is my database connection string. I did not set max pool size until now.
这是我的数据库连接字符串。直到现在我才设置最大池大小。
public static string srConnectionString =
"server=localhost;database=mydb;uid=sa;pwd=mypw;";
So currently how many connections does my application support? What is the correct syntax for increasing the connection pool size?
那么目前我的应用程序支持多少个连接?增加连接池大小的正确语法是什么?
The application is written in C# 4.0.
该应用程序是用 C# 4.0 编写的。
回答by Zaphood
Currently your application support 100 connections in pool. Here is what conn string will look like if you want to increase it to 200:
目前您的应用程序在池中支持 100 个连接。如果您想将其增加到 200,则 conn 字符串将如下所示:
public static string srConnectionString =
"server=localhost;database=mydb;uid=sa;pwd=mypw;Max Pool Size=200;";
You can investigate how many connections with database your application use, by executing sp_who
procedure in your database. In most cases default connection pool size will be enough.
您可以通过sp_who
在数据库中执行过程来调查您的应用程序使用了多少与数据库的连接。在大多数情况下,默认连接池大小就足够了。
回答by Laminar
"currently yes but i think it might cause problems at peak moments"I can confirm, that I had a problem where I got timeouts because of peak requests. After I set the max pool size, the application ran without any problems. IIS 7.5 / ASP.Net
“目前是的,但我认为它可能会在高峰时刻引起问题”我可以确认,我遇到了由于高峰请求而超时的问题。设置最大池大小后,应用程序运行没有任何问题。IIS 7.5 / ASP.NET
回答by Prashant Rai
We can define maximum pool size in following way:
我们可以通过以下方式定义最大池大小:
<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>