ado.net Closing Connection when using “using” statement

后端 未结 7 732
青春惊慌失措
青春惊慌失措 2020-11-27 07:46

I am doing my database access methods to SQL Server like this

  using (SqlConnection con = new SqlConnection(//connection string)
  {
    using (SqlCommand c         


        
7条回答
  •  一个人的身影
    2020-11-27 08:14

    As Phil said, the using clause will take care of it for you. When compiled down it wraps the connection create in a try .. finally and places the connection disposal call inside the finally.

    For more information you can see the using statement article at msdn.

提交回复
热议问题