How SqlDataReader Works underneath

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NickMak
    New Member
    • Sep 2013
    • 2

    How SqlDataReader Works underneath

    Hello ,my question is theoretical.
    When i make a request from the client(my PC) to the Server(SqlServe r),the data are sent back in packets.In my connection string i wrote:
    Packet Size = 512, which means that each packet(Result Set) will be equal to that.Plus my SqlServer and application are in the same box which means that the buffer is a shared memory in my PC.
    I execute this simple code :

    Code:
    con.open();
    SqlDataReader rdr= command.ExecuteReader();
    MyDataTable.Load(rdr);
    con.close();
    Then in debugging mode, i put a breakpoint to MyDataTable.Loa d(rdr);
    Now,if i hover my mouse over the rdr object, i m able to see all data from SqlServer in Result Views of the drop down list, which it s strange.
    I would expect only the first result set to see.
    Each datarow in SqlServer is about 50 bytes, so a Result Set would normally contain about 10-11 datarows. So, how am i able to see 2300 datarows ?
    Even if i scroll down to result number 1000, which means that definitely i am not in the first Result Set, i am able to go back and read my first DataRow.But since the SqlDataReader is not supposed to keep in memory
    all the results, how am i able to see all the results ?
    What am i missing here?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    The packets being sent are 512 bytes in size. But all packets must be sent before it moves from line 2 to line 3. It's not like there's a loop between line 2 and 3 that processes one packet and then jumps back to line 2.

    Comment

    Working...