Deallocation of SqlDataReader
问题 I have a contractor that wrote code like this all over the place when we execute sql queries: sql.Append(string.Format("SELECT TableId FROM ps_SavedTables WHERE guid = '{0}'", guid)); using (IDataReader reader = SqlHelper.GetDataReader(sql.ToString())) { if (reader.Read()) { result = reader.IsDBNull(0) ? string.Empty : reader[0].ToString(); } //CDW added to close SqlDataReader reader.Close(); } The GetDataReader class was in an App_Code helper file and is declared like so: public static