我正在使用 SQL Server 2008 数据库开发一个基于 ASP.NET 4.0、jQuery、AJAX、Javascript 的 Web 应用程序。我们的应用程序是一个 ERP 应用程序,大约有 400 到 500 个用户使用该应用程序。自一个月前以来,我们已经让它上线了。
现在,我面临一个超时问题,并且应用程序在使用几个小时后发生了字面上的崩溃。
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:
Line 36: param[1].Value = Password;
Line 37:
Line 38: return SqlHelper.ExecuteDataset(CDSGlobal.ConnectionString, CommandType.StoredProcedure, "ValidateLogin_sp", param);
Line 39: }
Line 40:
Source File: e:\abcd\App_Code\User.cs Line: 38
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) +6352273
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6352606
System.Data.SqlClient.SqlConnection.Open() +300
DBConn.SqlHelper.ExecuteDataset(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters) +270
User.ValidateLogin(String Employee_Code, String Password) in e:\abcd\App_Code \User.cs:38
User_UserLogin.btnLogin_Click(Object sender, EventArgs e) in e:\abcd \User\UserLogin.ascx.cs:79
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
对于临时解决方案,我们正在重新启动服务器并重新启动MSSQLSERVER
服务。
经过上面的搜索,我才知道这是由于连接泄漏。一些打开的连接永远不会关闭。
我正在为 .NET 使用现成的 Microsoft 数据访问应用程序块,即 SQLHelper 类,它在我的应用程序中使用 Dataset 和所有数据访问数据。
注意:我不在SqlDataReader
任何地方使用。
我检查了该类及其关闭连接,但我从未使用过手动连接代码,而是到处使用 SQLHelper。
我在存储过程中也有以下嵌套事务结构,如下所示:
BEGIN TRY
BEGIN TRANSACTION
-- Every below stored procedure has the transation structure as this SP i.e. Parent SP. (BEGIN TRY, BEGIN TRANSACTION etc)
exec sp1
exec sp2
exec sp3
---
---
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF @@TRANCOUNT>0
ROLLBACK TRANSACTION
PRINT 'ERROR OCCURED In SP'
END CATCH
现在,问题是为什么会发生连接泄漏。
上面的事务结构是负责的,即它阻塞了事务和请求。
如果请求正在处理中并且用户已关闭浏览器,应用程序是否会关闭连接?
任何帮助将不胜感激。