Do I have to close the SQL Connection manually if I use Linq?

前端 未结 3 578
我在风中等你
我在风中等你 2020-12-06 07:15

Traditionally, when we use SQL string to done some work, we have to close the sql connection before the page being closed, I was wondering if I use Linq to do the data opera

3条回答
  •  孤街浪徒
    2020-12-06 07:37

    In code you need not open and close connections. However, IMO a LinqDataContext should be treated as a resource like SqlConnection or SqlCommand and should be a part of the using block so that you dispose it when not using. Even though I have read on MSDN that this is not necessary but it is a good practice.

提交回复
热议问题