When should I open and close a connection to SQL Server

前端 未结 6 1033
慢半拍i
慢半拍i 2020-12-12 19:09

I have a simple static class with a few methods in it. Each of those methods open a SqlConnection, query the database and close the connection. This way, I am sure that I al

6条回答
  •  一个人的身影
    2020-12-12 20:11

    In your code sample there is no need to call the close() method on the connection object as it will be handled automatically due to the code residing inside a using block.

提交回复
热议问题