Best practice for reusing SqlConnection

后端 未结 5 2079
误落风尘
误落风尘 2021-01-17 09:43

I\'ve come from Java experience and am trying to start with C#. I\'ve read SqlConnection SqlCommand SqlDataReader IDisposable and I can understand that the best practice to

5条回答
  •  既然无缘
    2021-01-17 10:19

    MS SQL server manages connections in it's own connection pool, and they aren't actually disposed. But they are closed so you minimize the network traffic and release the available connections to your server.

    Also you should note that if you are using the Linq-To-SQL, the data context will not release the connection until being disposed, so I suggest you just use already working code and do not try to optimize it by yourself.

提交回复
热议问题