When should I open and close a connection to SQL Server

前端 未结 6 1019
慢半拍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 19:59

    Don't ever rely on the connection to close itself. If it's not explicitly closed, it will lead to performance issues. It happened to us on our project. Yes, I'm aware that connections are managed by a connection pool, but they still have to be closed and returned to the pool.

提交回复
热议问题