I agree with sloan. One of the most common posts we get on our forums (and
also that I see here) is running out of connection pool because of rampant
DataReaders that have never been closed.
If you want, you can convert the DatarReader into a DataTable, return that,
and close the reader and the connection before your data ever gets outside
the method it was created in.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Ronald S. Cook" wrote:
> In my middle tier, I, of course, often return data to the presentation
> layer. When needing a forward-only, read-only list, I think of the
> SqlDataReader (of course). However, since you can't close the connection
> before returning the data, the line at the end of the function is what I've
> found to use (i.e. CommandBehavior.CloseConnection). HOWEVER, I've heard
> this sometimes doesn't always work properly and I should stick to using
> DataTables instead.
>
>
>
> Have you heard this? Or, do you think the below is just fine?
>
>
>
> *****************************************************
>
> Public Function UserList(ByVal iclientno As Integer) As SqlDataReader
>
>
>
> 'Return the list of userid from the user table based on a client number.
>
>
>
> Dim dbConnection As New
> SqlConnection(ConfigurationSettings.AppSettings("ConnectionStringKamtechLogin"))
>
> Dim spCommand As New SqlCommand("spGetUsers", dbConnection)
>
> spCommand.CommandType = CommandType.StoredProcedure
>
>
>
> Dim paramClientNo As New SqlParameter("@ClientNo", SqlDbType.Int)
>
> spCommand.Parameters.Add(paramClientNo)
>
> paramClientNo.Direction = ParameterDirection.Input
>
> paramClientNo.Value = iclientno
>
>
>
> dbConnection.Open()
>
>
>
> Dim dr As SqlDataReader =
> spCommand.ExecuteReader(CommandBehavior.CloseConnection)
>
>
>
> Return dr
>
>
>
> End Function
>
> *****************************************************
>
>
>
> Thanks,
>
> Ron
>
>
>
>
>
>
>
>
>