I'm executing several queries and monitoring the server I see connections stay open for a while (3-5 minutes?) after the End Using
statment.
Is this a normal behaviour of using
statement?
My query execution uses a custom class bdConex and looks something like:
Dim cnx As New bdConex({Id})
Using cnx.conexionBD
cnx.query("MyStoredProcedure")
If cnx.dataReader.Read Then
Me.Id = cnx.item(Of Integer)("fk_item")
Me.Number= cnx.item(Of String)("number")
End If
End Using
cnx.close()
Where:
Public Class bdConex
Public Property conexionBD As SqlConnection
Public Property dataReader As SqlDataReader
Public Sub query(ByVal ssql As String)
If InStr(ssql, "select", CompareMethod.Text) <> 1 Then
ssql = String.Concat("Exec ", parseSQL(ssql))
End If
If Me.ActivarLog = TipoDeLog.ErroresYConsultas Then
logger.log(ssql, "bdConex.query()")
End If
Try
Using Me.conexionBD
Me.conexionBD = New SqlConnection(Me.cadena_de_conexion)
Me.conexionBD.Open()
Dim myCommand As SqlCommand = New SqlCommand(ssql, Me.conexionBD)
Me.dataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Me.HasRows= Me.dataReader.HasRows
End Using
Catch ex As Exception
Me.HasRows = False
'log error
End Try
End Sub
Thanks