我知道有很多例子,其中定义了 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
}
不,SqlCommand 从不尝试关闭/处置连接。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)