Will ExecuteReader(CommandBehavior.CloseConnection) always close connection?

后端 未结 5 977
栀梦
栀梦 2021-01-11 14:27

Is it safe to write this helper method like this? Will it always close the connection? I understend if all goes well, it will, but will ExecuteReader close the connection ev

5条回答
  •  我在风中等你
    2021-01-11 15:23

    Personally I prefer a using clause statement to close/dispose the connection , simply for parallel construction reasons - same as in good English Grammar.
    From my point of view using the CommandBehavior is not balanced and therefore unpredictable.

    I constantly tell to my developers to go simple and consistent.
    As if they forget to set the CommandBehavior...

    I won't see it...
    but if they don't use a using statement...
    I will see it as it is very important.

提交回复
热议问题