我知道很多例子都是在Using块中定义了SqlConnection,然后又定义了一个SqlCommand:
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
}