【发布时间】:2010-09-29 10:35:40
【问题描述】:
我知道在使用块中定义了 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
}
【问题讨论】:
标签: c# using using-statement