A
andre luiz via .NET 247
Hello Everybody,
Can someone help me? I'm not sure about the code below. It'sworking but... . I create a new OledbConnection, opened andcalled a method. This method creates a new OleDbCommand that usethe connection (via another class; cn is a member in an dataclass). But the OleDbCommand is not disposed after the method isfinished (should I dispose it?). After that, the connection isdisposed. See below:
' Creates and open a connection
Dim cn as OleDb.OleDbConnection
cn = New OleDb.OleDbConnection(strConn)
cn.Open()
' call method
retDatTable()
' Dispose connection
cn.Dispose()
Function retDatTable(ByVal strSQL As String) As DataTable
Dim oDataTable As New DataTable()
Dim oOleDbCommand As OleDb.OleDbCommand
oOleDbCommand = New OleDb.OleDbCommand(strSQL, cn)
Dim oDataAdapter As New OleDb.OleDbDataAdapter(oOleDbCommand)
oDataAdapter.Fill(oDataTable)
Return oDataTable
End Function
The connection was disposed. But... the OleDbCommand that usedthe connection was not. This connection will be returned to thepool? I'm not sure because OleDbCommand was not disposed... so,he continue to hold the connection reference, right? Or I'mmissing something...??
Thanks!!
Andre
Can someone help me? I'm not sure about the code below. It'sworking but... . I create a new OledbConnection, opened andcalled a method. This method creates a new OleDbCommand that usethe connection (via another class; cn is a member in an dataclass). But the OleDbCommand is not disposed after the method isfinished (should I dispose it?). After that, the connection isdisposed. See below:
' Creates and open a connection
Dim cn as OleDb.OleDbConnection
cn = New OleDb.OleDbConnection(strConn)
cn.Open()
' call method
retDatTable()
' Dispose connection
cn.Dispose()
Function retDatTable(ByVal strSQL As String) As DataTable
Dim oDataTable As New DataTable()
Dim oOleDbCommand As OleDb.OleDbCommand
oOleDbCommand = New OleDb.OleDbCommand(strSQL, cn)
Dim oDataAdapter As New OleDb.OleDbDataAdapter(oOleDbCommand)
oDataAdapter.Fill(oDataTable)
Return oDataTable
End Function
The connection was disposed. But... the OleDbCommand that usedthe connection was not. This connection will be returned to thepool? I'm not sure because OleDbCommand was not disposed... so,he continue to hold the connection reference, right? Or I'mmissing something...??
Thanks!!
Andre