SqlConnection が定義され、次に SqlCommand が定義されている多くの例が、両方とも Using ブロックに存在することを知っています。
using (var conn = new SqlConnection(connString)) {
using (var cmd = new SqlCommand()) {
cmd.Connection = conn;
//open the connection
}
}
私の質問: SqlCommand で直接接続を定義すると、コマンドが破棄されたときに接続が閉じますか?
using (var cmd = new SqlCommand()) {
cmd.Connection = new SqlConnection(connString);
//open the connection
}