Quote:Most "best practices" tell us to open connections as late as possible (right before executing any SQL) and closing them as soon as possible (right after the last bit of data has been extracted.
using (SqlConnection conn = new SqlConnection(...)) { using(SqlCommand cmd = new SqlCommand(..., conn)) { conn.Open(); using(DataReader dr = cmd.ExecuteReader()) // or load a DataTable, ExecuteScalar, etc. { ... { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)