close db connections

  • Thread starter Thread starter Howard
  • Start date Start date
H

Howard

using (SqlConnection connection = new SqlConnection(constr))
{
using (SqlCommand command = new SqlCommand(com, connection))
{
//read from db
}
}


Is this sufficient to close db connections or do I need to add
connection.close()..

I know the object will be disposed after this statement but will it close
open db connections?

What is the best practice for running a sql query in asp.net

Thanks,
Howard
 
Hi Howard,

Dispose() will close your connection so there's not need to Close() as
well. Unlike Close(), Dispose() will also clear the connection's
ConnectionString, so be careful if you try and Open() it again.

HTH,

Chris
 
Back
Top