Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Star
12171 Points
1824 Posts
May 23, 2012 05:50 AM|LINK
You should use using statement for connection.
using (SqlConnection cn = new SqlConnection(connectionString)) { SqlCommand cm = new SqlCommand(commandString, cn) cn.Open(); cm.ExecuteNonQuery(); }
Check following thread:
C# - closing Sql objects best practice
urenjoy
Star
12171 Points
1824 Posts
Re: When should I close the connection?
May 23, 2012 05:50 AM|LINK
You should use using statement for connection.
using (SqlConnection cn = new SqlConnection(connectionString)) { SqlCommand cm = new SqlCommand(commandString, cn) cn.Open(); cm.ExecuteNonQuery(); }Check following thread:
C# - closing Sql objects best practice