Buongiorno a tutti!
Ho ereditato in gestione un sito in asp.net. Da quando i gestori del server hanno cambiato la macchina, il sito mi dà errore sul pool di connessioni.
Questa è la classe per le connessioni:
codice:Public Class DBgest
Private _sql As String
Private _contarighe As String
Private cn As New SqlConnection()
Public Property sql() As String
Get
Return _sql
End Get
Set(ByVal value As String)
_sql = value
End Set
End Property
Public Function apridati() As SqlDataReader
Dim mytable As New DataTable
Dim datiletti As SqlDataReader
Dim cmd As New SqlCommand
cn = New SqlConnection
cn.ConnectionString = ConfigurationManager.ConnectionStrings("sirio8sql").ConnectionString
cn.Open()
cmd.CommandText = _sql
cmd.CommandType = CommandType.Text
cmd.Connection = cn
datiletti = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return datiletti
End Function
Public Function contarighe() As Integer
Dim mytable As New DataTable
Dim datiletti
Dim cmd As New SqlCommand
cn = New SqlConnection
cn.ConnectionString = ConfigurationManager.ConnectionStrings("sirio8sql").ConnectionString
cn.Open()
cmd.CommandText = _sql
cmd.CommandType = CommandType.Text
cmd.Connection = cn
datiletti = cmd.ExecuteReader(CommandBehavior.CloseConnection)
mytable.Load(datiletti)
Return mytable.Rows.Count
End Function
Public Function esegui() As Integer
Dim nraffected As Integer
Dim cmd As SqlCommand
cn = New SqlConnection
cn.ConnectionString = ConfigurationManager.ConnectionStrings("sirio8sql").ConnectionString
cn.Open()
cmd = New SqlCommand
cmd.CommandText = _sql
cmd.CommandType = CommandType.Text
cmd.Connection = cn
nraffected = cmd.ExecuteNonQuery()
Return nraffected
End Function
Public Function nonull(ByVal valore, ByVal restituzione)
If valore Is DBNull.Value Then
Return restituzione
Else
Return valore
End If
End Function
Public Function nonullorblank(ByVal valore, ByVal restituzione)
If valore Is DBNull.Value Then
Return restituzione
Else
If Trim(valore) = "" Then
Return restituzione
Else
Return valore
End If
End If
End Function
Public Function estrai(ByVal colonna As String, ByVal tabella As String, ByVal campo_indice As String, ByVal valore_indice As String) As String
Dim datiletti As SqlDataReader
Dim cmd As New SqlCommand
Dim valore As String = ""
cn = New SqlConnection
cn.ConnectionString = ConfigurationManager.ConnectionStrings("sirio8sql").ConnectionString
cn.Open()
cmd.CommandText = "select " & colonna & " from " & tabella & " where " & campo_indice & "=" & valore_indice
'HttpContext.Current.Response.Write(cmd.CommandText)
'HttpContext.Current.Response.End()
cmd.Connection = cn
datiletti = cmd.ExecuteReader(CommandBehavior.CloseConnection)
For Each i In datiletti
valore = datiletti(colonna).ToString
Next
cn.Close()
cn = Nothing
cmd = Nothing
Return valore
End Function
Public Sub DBchiudi()
cn.Close()
cn = Nothing
End Sub
End Class
Ho verificato che tutte le aperture della classe DBGest avessero il metodo DBchiudi, tranne nel caso in cui viene richiamato il metodo estrai, poichè la connessione viene aperta e chiusa nello metodo stesso.
Nonostante tutto, dopo un paio di giorni, l'errore si è ripresentato, nonostante un Max Pool Size reimpostato a 200...
Devo aggiungere il Dispose() alla classe DBchiudi?