G
Guest
Is the following code a valid way of passing a DataReader object back to
calling code? I'm specifically concerned with the objConn object be
explicitly set to Nothing. Does this cause the connection object to be
garbage collected or does the connection object not get destroyed until the
calling code closes the DataReader object (and thus the connection object)?
Public Function GetDataReader(ByVal strSelect As String) As
OleDbDataReader
Try
objConn = New OleDbConnection(strConnectionString)
objCmd = New OleDbCommand(strSelect, objConn)
objCmd.Connection.Open()
GetDataReader =
objCmd.ExecuteReader(CommandBehavior.CloseConnection)
Catch ex As OleDbException
GetDataReader = Nothing
Finally
objConn = Nothing
objCmd = Nothing
End Try
End Function
calling code? I'm specifically concerned with the objConn object be
explicitly set to Nothing. Does this cause the connection object to be
garbage collected or does the connection object not get destroyed until the
calling code closes the DataReader object (and thus the connection object)?
Public Function GetDataReader(ByVal strSelect As String) As
OleDbDataReader
Try
objConn = New OleDbConnection(strConnectionString)
objCmd = New OleDbCommand(strSelect, objConn)
objCmd.Connection.Open()
GetDataReader =
objCmd.ExecuteReader(CommandBehavior.CloseConnection)
Catch ex As OleDbException
GetDataReader = Nothing
Finally
objConn = Nothing
objCmd = Nothing
End Try
End Function