I know it's "best practice" to dispose ado.net objects, but does it make a big difference if just the connection is closed?
In other words, is the code below good enough or should the DataAdapter & Command be explicitly closed?
using (SqlConneciton cn = new SqlConnection(connstr))
{
SqlDataAdapter da = new SqlDataAdapter(sql,cn);
DataSet ds = new DataSet();
da.Fill(ds);
SqlCommand cmd = new SqlCommand(someOtherSql,cn);
cmd.ExecuteNonQuery();
}
Hi John,
Actually, you don't need to call dispose. The Dispose method is used to release unmanaged resources. Since Close has already been called, the connection will be put back to pool automatically.
IMO, just call Close. That's enough. If you're using "using" statement, it's better. It will call dispose automatically.
HTH. If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!
No comments:
Post a Comment