Using SqlDataReader Records After Deletion

I would like to get everything System.Data.IDataRecord

out SqlDataReader

. It's simple with LINQ, but I would like to be able to delete all SQL objects and keep the data intact. Below is what I have:

private static List<System.Data.IDataRecord> getRecords()
    List<System.Data.IDataRecord> records;
    //Make a SqlConnection and SqlCommand.
    using (SqlDataReader reader = command.ExecuteReader())
        records = reader.Cast<System.Data.IDataRecord>().ToList();
    //Dispose of SqlCommand and SqlConnection.
    return records;


But here is my question: when getRecords()

finished, I have my data and I asked all SQL objects to be deleted. But am I somehow hung up on data that will prevent the proper destruction of resources? Or will my data end up being invalid after the garbage collector does its job? I think the answer is no, but I am trying to find something definitive. I believe it Dispose()

will remove unmanaged resources, and since I put the data in my list, I would think it was safe. Thank.


source to share

1 answer

This will work fine.


instances have no effect on SqlDataReader.Dispose

. They contain their complete data and schema information completely separate from the reader.



All Articles