How DataReader works?

前端 未结 4 627
感动是毒
感动是毒 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:40

    The data reader reads a record at a time, but it reads it from the underlying database driver. The database driver reads data from the database in blocks, typically using a buffer that is 8 kilobytes.

    If your result records are small and you don't get very many, they will all fit in the buffer, and the database driver will be able to feed them all to the data reader without having to ask the database for more data.

    If you fetch a result that is larger than the buffer, you will only be able to read the first part of it, before the database driver needs to ask the database for more data. At that time you will get an exception if the database is no longer accessible.

提交回复
热议问题