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()) { ... }
1.4m articles
1.4m replys
5 comments
57.0k users