Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
using(var reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { while(reader.read()) { //calculations } }
什么时候会关闭连接以及是否累积打开连接?
如文档中所述:
执行命令时,Connection关闭关联对象时关闭关联DataReader对象。
Connection
DataReader
在您的情况下,连接将在 using 块的末尾关闭。