使用说明和关闭方法 [英] Using statement and Close methods

查看:250
本文介绍了使用说明和关闭方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

难道using语句真正调用close方法与数据库连接对象使用时? MSDN文档说,这可以确保调用Dispose方法,但并没有提及接近。我看到堆栈溢出的帖子里的人说,它确实两者兼而有之。是否有人有一个具体的答案一对这个来自微软或其他确凿的证据拉上它呢?

Does the using statement really call the close method when used with a database connection object? The MSDN documentation says it ensures that the Dispose method is called but makes no mention of close. I see posts on Stack Overflow where people say that it does both. Does someone have a concrete answer one way or another on this from Microsoft or other solid proof that it does?

推荐答案

下面是SqlConnection类的处置的方法:

Here is the "Dispose" method of the SqlConnection class:

protected override void Dispose(bool disposing)
{
    if (disposing)
    {
        this._userConnectionOptions = null;
        this._poolGroup = null;
        this.Close();
    }
    this.DisposeMe(disposing);
    base.Dispose(disposing);
}

正如你所看到的,它确实调用close()

As you can see, it does indeed call Close()

这篇关于使用说明和关闭方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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