What are best practices on managing database connections in .NET?

后端 未结 4 1440
轻奢々
轻奢々 2020-12-31 11:45

Regarding best practice for managing database connections in a .NET application -- I know that, in general, it\'s bad to pass around a connection object.

However, I

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 12:09

    This link may be helpful: Best Practices for Using ADO.NET

    Here's an interesting excerpt.

    For best performance, keep connections to the database open only when required. Also, reduce the number of times you open and close a connection for multiple operations.

    I've always followed the practice of opening connections in a using block, so that the Dispose method (and hence the Close method) is always called without my worrying about it. Using this approach I've never encountered a situation where poor performance was linked either to excessive concurrent connections or excessive setup or tear down operations.

提交回复
热议问题