C# - closing Sql objects best practice

前端 未结 8 1026
陌清茗
陌清茗 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条回答
  •  旧时难觅i
    2020-12-31 12:02

    Any class handling SQL stuff like Connections should implement the IDisposable interface as stated by Microsoft .NET coding guidelines.

    Thus, you should probably close and dispose your connection in your Dispose method.

提交回复
热议问题