Will ExecuteReader(CommandBehavior.CloseConnection) always close connection?

后端 未结 5 963
栀梦
栀梦 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:02

    Yes it will (inside a using block like you're doing). But to access the data you probably want to use While DbDataReader.read instead of iterating over its contents.

提交回复
热议问题