最终是否采用关闭打开的SQL连接 [英] Does End Using close an open SQL Connection

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

问题描述

如果我换了使用的SQLConnection,我应该关闭它还是最终用处理呢?

 使用CN作为新system.data.sqlclient.sqlconnection()
    cn.open
    {做了一堆其他的东西与命令和的DataReader这里}
    cn.close'我需要吗?
最终使用
 

解决方案

(在你的榜样 CN )退出using块调用.Dispose()所讨论的对象这对于一个SqlConnection将关闭连接,所有打开的资源。

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

解决方案

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天全站免登陆