[dba-VB] c# - close in any particular order?

jwcolby jwcolby at colbyconsulting.com
Mon Feb 14 19:24:18 CST 2011


I have a connection, a command object and a data reader (all SQL objects).  Do I need to close them 
in any specific order?

ATM the code does this:

SqlDataReader dr;
SqlConnection cnn = new SqlConnection(clsGlobals.myConnection);
cnn.Open();
SqlCommand cmd = new SqlCommand(SQL, cnn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
}
cnn.Dispose();
cnn.Close();
cmd.Dispose();
dr.Dispose();
dr.Close();


-- 
John W. Colby
www.ColbyConsulting.com



More information about the dba-VB mailing list