[英]Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. Enterprise Library
[英]Enterprise Library 5.0 Connection Pool Timeout
我有一個用ASP.Net 2.0 Web窗體編寫的舊Web應用程序。 我使用企業庫中的數據訪問塊,並且最近已更新到版本5.0。 應用程序是分層的,即,UI層,服務層,數據層。 它還使用SQL Server 2008進行數據存儲。
我最近注意到,當我運行應用程序並瀏覽到特定頁面時,出現以下錯誤。
超時時間已到。 從池中獲取連接之前已經過超時時間。 這可能是因為所有池化連接都在使用中,並且達到了最大池大小。
這往往發生在從數據庫中進行大量單獨讀取的頁面上,一頁上最多可能多達20個。
下面顯示了我的數據訪問類的摘要。
Public Class DataAccess
' create a private instance of the database factory
Private db As Database = DatabaseFactory.CreateDatabase()
Public Function ExecuteNonQuery(ByVal params() As SqlParameter, ByVal strSproc As String) As Integer
Dim intReturnValue As Integer = 0
Dim i As Integer
Dim cmd As DbCommand
cmd = db.GetStoredProcCommand(strSproc)
cmd.CommandTimeout = 120
For i = 0 To params.Length - 1
db.AddInParameter(cmd, params(i).ParameterName.ToString, params(i).DbType, params(i).Value)
Next
db.AddParameter(cmd, "return_value", DbType.Int32, ParameterDirection.ReturnValue, "", DataRowVersion.Default, 0)
db.ExecuteNonQuery(cmd)
intReturnValue = Int32.Parse(db.GetParameterValue(cmd, "@return_value"))
Return intReturnValue
End Function
Public Function ExecuteDataReader(ByVal params() As SqlParameter, ByVal SProc As String) As SqlDataReader
Dim i As Integer
Dim dr As SqlDataReader = Nothing
Dim cmd As DbCommand
cmd = db.GetStoredProcCommand(SProc)
cmd.CommandTimeout = 120
For i = 0 To params.Length - 1
db.AddInParameter(cmd, params(i).ParameterName.ToString, params(i).DbType, params(i).Value)
Next
dr = TryCast(DirectCast(db.ExecuteReader(cmd), RefCountingDataReader).InnerReader, SqlDataReader)
Return dr
End Function
在我的整個代碼中,一旦完成SqlDataReader,我總是會執行以下操作
If Not (drSource Is Nothing) Then
drSource.Close()
End If
你們有什么可以看到我失蹤的東西嗎? 看起來我的代碼可能會泄漏連接或無法正確關閉?
我一直認為垃圾收集器擺脫了任何開放的聯系。
任何反饋或幫助將不勝感激。
謝謝。
您的代碼正在關閉數據讀取器,但沒有關閉與之關聯的數據連接。
由於您的數據讀取器是SqlDataReader
,因此它具有Connection
屬性。 您應該能夠使用它來關閉和處置連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.