Question

all we know that datareader works like

The datareader 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 and when there will no data exist in network buffer then datareader will inform sql server to send next block of data.

here is small code how we use data reader

String selectString = "SELECT * FROM PRODUCT";  
    IList<client> clients = new List<client>();  
    using (var selectCommand = new OracleCommand(connection, selectString))  
    {  
        using (OracleDataReader selectReader = selectCommand.ExecuteReader())  
        {   
           if (selectReader.HasRows)  
           {  
               while (selectReader.Read())  
               {  
                   clientes.add( GetDomainObject(selectReader) );  
               }  
               selectReader.close();  
           }  
        }
    }  

suppose PRODUCT table has 10,000 records. so i like to know how much data can accommodate in network buffer at a time?

because when datareader.ExecuteReader() will call then reader will fetch a block of data and stored in network buffer in that pc. when datareader.read() will call then single data will be forwarded to reader from buffer. when all read wil be read from buffer then a database call will made again and next block of data will be stored in buffer.

i am just curious to know how much data a data reader can stored in buffer when data fetch from db. data reader will always fetch a fixed number of rows from db & stored in buffer or does it depend on buffer size?

buffer size depend on what....does it depend on ram ?

please discuss only the network buffer related things because i know how data reader works. thanks

Was it helpful?

Solution

Depending on your setup have a read of this Default Result Set Processing and Multiple Active Result Sets and Rowsets and SQL Server Cursors

Look into TcpClient.ReceiveBufferSize it will tell you how much raw data can be read in one operation.

"The ReceiveBufferSize property gets or sets the number of bytes that you are expecting to store in the receive buffer for each read operation. This property actually manipulates the network buffer space allocated for receiving incoming data.

Your network buffer should be at least as large as your application buffer to ensure that the desired data will be available when you call the NetworkStream.Read method. Use the ReceiveBufferSize property to set this size. If your application will be receiving bulk data, you should pass the Read method a very large application buffer.

If the network buffer is smaller than the amount of data you request in the Read method, you will not be able to retrieve the desired amount of data in one read operation. This incurs the overhead of additional calls to the Read method."

and then read about NetworkStream.Read

At which point you will have a better idea of the complexity of the answer to your question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top