locked
sqldatareaders in ent lib 6.0 RRS feed

  • Question

  • User-1952414456 posted

    Hi,

    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.Dispose()
                objCommand = Nothing
    
                Return DirectCast(reader.InnerReader, SqlDataReader)
    
     End Function

    Monday, January 27, 2014 10:06 AM

All replies

  • User753101303 posted

    Hi,

    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) :

    http://msdn.microsoft.com/en-us/library/dn169621.aspx

     

    Monday, January 27, 2014 11:04 AM