Do I need to dispose a sqldatareader after it is created?
SqlDataReader reader; --- --- --- reader.Close(); reader.Dispose();
Rule of thumb: if a class implements IDisposable you should always call the Dispose method as soon as you have finished using this resource. Even better wrap it in a using statement to ensure that the Dispose method will be called even if an exception is thrown:
using (var reader = conn.ExecuteReader()) { ... }
2.1m questions
2.1m answers
60 comments
57.0k users