最近在项目遇到一个很头疼的问题,asp.net网站发布以后,开始运行正常,但是过一段时间就不能访问,而且还要报错。
错误代码如下:
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
Server Error in '/' Application.
Timeout expired. The timeout period elapsed prior to obtaining a
connection from the pool. This may have occurred because all pooled connections
were in use and max pool size was reached.
Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code.
Exception Details:
System.InvalidOperationException: Timeout expired. The timeout period
elapsed prior to obtaining a connection from the pool. This may have occurred
because all pooled connections were in use and max pool size was
reached.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.]
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4863722
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
Fdays.DBUtility.MSSqlHelper.CreateSqlConn() +86
Fdays.DBUtility.BaseHelper.GetDataSet(String strSql, String strTableName) +121
Fdays.DBUtility.BaseHelper.GetDataSet(String strSql) +49
Fdays.DBUtility.BaseHelper.GetDataTable(String strSql) +55
Fdays.SqlServerDal.News.DNews.GetNewsList(MO_news mo_news, String strWhere, Int32 num) in F:\FdaysB2C\Fdays.VacationB2C\Fdays.SqlServerDal\News\DNews.cs:339
Fdays.Bll.News.BNews.GetNewsList(MO_news mo_news, String strWhere, Int32 num) in F:\FdaysB2C\Fdays.VacationB2C\Fdays.Bll\News\BNews.cs:151
Fdays.SiteBuild._Default.Page_Load(Object sender, EventArgs e) in F:\FdaysB2C\Fdays.VacationB2C\Fdays.WebApp\Default.aspx.cs:40
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
Fdays.SiteBuild.Public.Core.BasePage.OnLoad(EventArgs e) in F:\FdaysB2C\Fdays.VacationB2C\Fdays.WebApp\Public\Core\BasePage.cs:353
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Version Information: Microsoft .NET Framework Version:2.0.50727.3082;
ASP.NET Version:2.0.50727.3082
应用池设置太小.建议在数据连接字符串加上下面两个属性:
Packet Size=8192;Max Pool Size=1000;
找找你的代码数据库连接是怎么写的
用过的资源是否即时关闭了
否则的连接池满
数据溢出你就用不了了
重点检查一下你的DataReader,是否用过,没有关闭连接,导致连接池满了;
推荐:
using (SqlDataReader dr = SQLHelper.ExecuteReader(cmdText))
{用这种方式更好}
但是连接数可达到600多个,这个值正常吗?也太多了,建议检查连接是否断开,你可以进到SQL里面看一下,那些进程ID没释放掉,然后你就在你的程序里面改一下对应的ID,是否用完后就断开连接