答案在于使用关键字的行为。退出使用块时,在包含的对象上调用.dispose()方法。对于sqlConnection,.dispose()自动关闭连接并发布任何关联的资源。
]使用cn作为new System.data.sqlclient.sqlConnection() CN.OPEN '{在此处使用命令和dataReaders的其他一些事情} cn.close'我需要这个吗? end using
Explanation:The using block in this example automatically closes the SQLConnection object named cn when the block is exited.因此,在使用块之后向.close()的明确调用是冗余且不必要的。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3