Best practice? open and close multi connections, or one large open connection for ado.net

前端 未结 4 1318
一个人的身影
一个人的身影 2021-01-02 00:44

I am using ADO.Net for some database connectivity and I was just hoping I was doing it the right way. I am opening and closing multiple connections for each stored procedur

4条回答
  •  再見小時候
    2021-01-02 01:16

    You should keep connections open as short a time as possible. Thus, you want to open a connection, execute a query or stored procedure and then close the connection. Although this sounds expensive, it leverages ADO.NET's built-in connection pooling. When you close a connection, it is returned to a pool and reused so you do not suffer a performance hit.

提交回复
热议问题