What is Best Approach for Opening/Closing SqlConnection in C#

后端 未结 3 1678
粉色の甜心
粉色の甜心 2021-01-23 06:36

I would like to know what could be best approach to open a SqlConnection with Sql Server 2008R2 Express Edition Database. This Version of Sql has Limit

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-23 07:25

    Just use using as it disposes of the connection once done.

     using(SqlConnection conn = new SqlConnection("Connection string")){
      //do sql stuff
      conn.Open(); 
      //etc etc
      conn.Close();
     }
    

提交回复
热议问题