C# - closing Sql objects best practice

前端 未结 8 1020
陌清茗
陌清茗 2020-12-31 11:29

If you have a C# function with Sqlaccess, is it mandatory to close all objects/handles, or is everything cleaned up automatically once you exit the function

For exam

8条回答
  •  长发绾君心
    2020-12-31 12:04

    Calling Close on the SQL connection won't actually close it, but will return it to a connection pool to be reused, improving performance.

    Additionally it is generally poor practice to not explicitly dispose of unmanaged resources when you are finished with them (asap).

提交回复
热议问题