Does End Using close an open SQL Connection

前端 未结 6 1509
礼貌的吻别
礼貌的吻别 2020-11-29 05:53

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
           


        
6条回答
  •  暖寄归人
    2020-11-29 06:06

    "A Using block behaves like a Try...Finally construction in which the Try block uses the resources and the Finally block disposes of them. Because of this, the Using block guarantees disposal of the resources, no matter how you exit the block. This is true even in the case of an unhandled exception, except for a StackOverflowException."
    https://msdn.microsoft.com/en-us/library/htd05whh.aspx

提交回复
热议问题