K
Klaus Jensen
Hi!
If I have a class, and I have a connection property, which I use to access
the database...
How do you make sure, the connection is returned to the connection pool?
Must I make the connection public and explicitly close it, when I am done
with the class? Or is it enough to add Me.connection.close in Protected
Overrides Sub Finalize()??
Fx:
Public Class Forhandler
Private _strConnectionString As String =
ConfigurationSettings.AppSettings("Connectionstring")
Private Shared _cnnConnection As SqlConnection
Private Shared Property Connection() As SqlConnection
Get
If Not _cnnConnection.State = ConnectionState.Open Then
_cnnConnection.Open()
End If
Return _cnnConnection
End Get
Set(ByVal cnnConnection As SqlConnection)
_cnnConnection = cnnConnection
End Set
End Property
'..Some properties
Public Sub DoStuffInTheDatabase()
''Using me.connection
End Sub
Public Sub DoMoreStuffInTheDatabase()
''Using me.connection
End Sub
Protected Overrides Sub Finalize()
Me.Connection.Close()
MyBase.Finalize()
End Sub
End Class
If I have a class, and I have a connection property, which I use to access
the database...
How do you make sure, the connection is returned to the connection pool?
Must I make the connection public and explicitly close it, when I am done
with the class? Or is it enough to add Me.connection.close in Protected
Overrides Sub Finalize()??
Fx:
Public Class Forhandler
Private _strConnectionString As String =
ConfigurationSettings.AppSettings("Connectionstring")
Private Shared _cnnConnection As SqlConnection
Private Shared Property Connection() As SqlConnection
Get
If Not _cnnConnection.State = ConnectionState.Open Then
_cnnConnection.Open()
End If
Return _cnnConnection
End Get
Set(ByVal cnnConnection As SqlConnection)
_cnnConnection = cnnConnection
End Set
End Property
'..Some properties
Public Sub DoStuffInTheDatabase()
''Using me.connection
End Sub
Public Sub DoMoreStuffInTheDatabase()
''Using me.connection
End Sub
Protected Overrides Sub Finalize()
Me.Connection.Close()
MyBase.Finalize()
End Sub
End Class