我目前正在开发一个应用程序,用户登录该应用程序以查看/编辑多种类型的报告,以便其他用户可以查看已进行的更改。但有时当用户进入新页面时,会话会自动超时。
我的代码是:
Function Check_Access(ByVal strModule As String) As String
Dim drAccess As SqlClient.SqlDataReader, strUser As String
GetNetworkName()
strUser = HttpContext.Current.Session("LOGON_USER")
drAccess = SqlHelper.ExecuteReader(strConnOASIS, "Oasis.dbo.p_RPT_Check_Accessibility", strModule, strUser)
If drAccess.HasRows Then
If drAccess.Read() Then
Return drAccess.GetString(0)
End If
End If
drAccess.Close()
Return "0"
End Function
源错误是:
Line 45: strUser = HttpContext.Current.Session("LOGON_USER")
Line 46:
Line 47: drAccess = SqlHelper.ExecuteReader(strConnOASIS, "Oasis.dbo.p_RPT_Check_Accessibility", strModule, strUser) //Error
Line 48:
Line 49: If drAccess.HasRows Then
最后是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.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +445
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +318
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +132
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +195
System.Data.SqlClient.SqlConnection.Open() +122
Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters) +412
Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(String connectionString, String spName, Object[] parameterValues) +442
OasisInclude.GlobalFunctions.Check_Access(String strModule) in E:\Danish\VSO\OasisRedesign\Dev\Oasis\OasisInclude\GlobalFunctions.vb:47
Residential.Residential.Page_Load(Object sender, EventArgs e) in E:\Danish\VSO\OasisRedesign\Dev\Oasis\Oasis\Residential\Residential.aspx.vb:56
System.Web.UI.Control.OnLoad(EventArgs e) +109
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3321
答案 0 :(得分:0)
如果数据读取器返回数据,则永远不会关闭它。所有这些开放数据读取器都在保持数据库连接,从而导致错误。
要解决此问题,请将代码更改为:
Function Check_Access(ByVal strModule As String) As String
Dim drAccess As SqlClient.SqlDataReader, strUser As String
GetNetworkName()
strUser = HttpContext.Current.Session("LOGON_USER")
drAccess = SqlHelper.ExecuteReader(strConnOASIS, "Oasis.dbo.p_RPT_Check_Accessibility", strModule, strUser)
Try
If drAccess.HasRows Then
If drAccess.Read() Then
Return drAccess.GetString(0)
End If
End If
Finally
drAccess.Close()
End Try
Return "0"
End Function