Since you coded "CommandBehavior.CloseConnection), the client should (must)
close the DataReader when it's done with it. This will close the Connection
(return it to the pool) and mark its resources for cleanup on next GC.
hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Todd Bright" <(E-Mail Removed)> wrote in message
news:C6C379CA-C095-404C-A792-(E-Mail Removed)...
> 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
>