Last post Jan 27, 2014 11:04 AM by PatriceSc
Jan 27, 2014 10:06 AM|aristotle|LINK
There is a change in ent library 6 where sqldatareaders dont seem to get returned like in previous versions of the library and we have to cast them into RefCountingDataReader.
But how do we reliably close the readers when using them in other parts of the code? The below code returns the inner reader but we have to close the outer reader?
Function that returns a SqlDataReader
Public Shared Function Users_Get() As SqlDataReader
Dim db As Database = DatabaseFactory.CreateDatabase()
Dim objCommand As SqlCommand = db.GetStoredProcCommand("dbo.Users_Get")
objCommand.CommandType = CommandType.StoredProcedure
Dim reader As RefCountingDataReader = DirectCast(db.ExecuteReader(objCommand), RefCountingDataReader)
objCommand = Nothing
Return DirectCast(reader.InnerReader, SqlDataReader)
Jan 27, 2014 11:04 AM|PatriceSc|LINK
My understanding is that you should return the RefCountingDataReader and that closing it will take care of whatever needs to be done for the inner reader and/or connection. You could likely check the source code (that is AFAIK available) to better understand
what it does (actually I'm not using this library) :