是否结束使用关闭打开的 SQL 连接 [英] Does End Using close an open SQL Connection

查看:25
本文介绍了是否结束使用关闭打开的 SQL 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将 SQLConnection 包装在 Using 中,我应该关闭它还是最终 using 处理它?<​​/p>

If I wrap a SQLConnection in a Using, should I close it or does the end using handle it?

using cn as new system.data.sqlclient.sqlconnection()
    cn.open
    '{do a bunch of other stuff with commands and datareaders here}
    cn.close 'Do I need this?
end using 

推荐答案

退出 using 块调用 .Dispose() 对有问题的对象(在您的示例中为 cn),对于 SqlConnection 将关闭连接和任何打开的资源.

Exiting a using block calls .Dispose() on the object in question (cn in your example) which for a SqlConnection will close the connection and any open resources.

这篇关于是否结束使用关闭打开的 SQL 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆