Folks
I have an N-Tiered ASP.Net Web Forms application which uses Enterprise Library 5.0 for data persistence. Recently I have noticed my application has been spitting out the following error
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool
This would point to leaking connections or connections not being closed. Please can someone look at my Data Access class and let me know if they see any issues where connections are not being closed properly
Public Class DataAccess
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
Using cmd As DbCommand = 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"))
End Using
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
Using cmd As DbCommand = 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)
End Using
Return dr
End Function
Public Function ExecuteDataSet(ByVal Sproc As String, ByVal params() As SqlParameter) As DataSet
Dim db As Database = DatabaseFactory.CreateDatabase()
Dim ds As New DataSet
Dim i As Integer
Using cmd As DbCommand = 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
db.LoadDataSet(cmd, ds, "table")
End Using
Return ds
End Function
Could this error also mean that it is taking too long to possibly execute some queries? Some tables in my database have alot of data in them.
Any feedback or help would be greatly appreciated with this folks as it is really affecting my application.
Thanks.