How DataReader works?

前端 未结 4 626
感动是毒
感动是毒 2020-11-28 12:17

I was thinking that the SQLDataReader should not work if there is no connection to the SQLServer.

I experimented this scenario. I execute the ExecuteReader then stop

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 12:24

    I strongly suspect that the reader reads a batch of results at a time. That's a lot more efficient than one row at a time (think about the situation where a single row is only a few bytes... you don't want a network packet per row when it could have retrieved lots of rows in a single packet). It also potentially allows the database to release its internal resources early - if the data reader has read all the results (when there are only a few) it can effectively forget about the query.

    I suspect if you try the same type of thing with a query returning lots of results, you'd get the expected exception.

提交回复
热议问题