最近几天,我们经常在网站上看到这样的错误信息:
“超时过期。超时时间
在获取
来自池的连接。这可能
已经发生是因为全部池化了吗
连接正在使用,马克斯泳池
规模达到了。”
我们已经有一段时间没有更改代码中的任何内容了。我修改了代码以检查未关闭的打开连接,但发现一切正常。
我怎么解决这个问题?
我需要编辑这个池吗?
如何编辑此池的最大连接数?
高流量网站的推荐值是多少?
更新:
我需要在IIS中编辑一些东西吗?
更新:
我发现活动连接的数量在15到31之间,我发现在SQL server中配置的最大允许连接数超过3200个连接,是31太多了还是我应该在ASP中编辑一些东西。网络配置?
除了公布的解决方案。
在处理1000页遗留代码时,每个代码都多次调用公共GetRS,这里有另一种解决问题的方法:
在现有的公共DLL中,我们添加了CommandBehavior。CloseConnection选择:
static public IDataReader GetRS(String Sql)
{
SqlConnection dbconn = new SqlConnection(DB.GetDBConn());
dbconn.Open();
SqlCommand cmd = new SqlCommand(Sql, dbconn);
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
然后,在每个页面中,只要关闭数据读取器,连接也会自动关闭,从而防止连接泄漏。
IDataReader rs = CommonDLL.GetRS("select * from table");
while (rs.Read())
{
// do something
}
rs.Close(); // this also closes the connection
您已经泄漏了代码上的连接。您可以尝试使用using来证明您正在关闭它们。
using (SqlConnection sqlconnection1 = new SqlConnection(“Server=.\\SQLEXPRESS ;Integrated security=sspi;connection timeout=5”))
{
sqlconnection1.Open();
SqlCommand sqlcommand1 = sqlconnection1.CreateCommand();
sqlcommand1.CommandText = “raiserror (‘This is a fake exception’, 17,1)”;
sqlcommand1.ExecuteNonQuery(); //this throws a SqlException every time it is called.
sqlconnection1.Close(); //Still never gets called.
} // Here sqlconnection1.Dispose is _guaranteed_
https://blogs.msdn.microsoft.com/angelsb/2004/08/25/connection-pooling-and-the-timeout-expired-exception-faq/