now that you know that nested datareaders over the same connection is a bad idea, why are you even doing that? do refactor that code.
now to answer your question,
Network layer does not work in PULL mode. You open a connection, issue some command and then start consuming the results. Note you do NOT pull but consume. there is a difference. in your code, while(reader.Read)
loop does not steadily pull data. the data starts arriving the moment the command is executed. it gets buffered at your pc. The buffer has a limit. if total data is less than the buffer size then the data-transfer happens really fast. if total data is more than the buffer size then of course the reader.read()
makes room for next batch.
This means that two DataReaders
can work with same connection
as long as the first datareader fetches very little amount of data. so by the time the second datareader attempts to use the connection the connection has already gone idle.
there is a race condition between two threads. first thread is the one which collects the data sent in response to the first command. the second thread is the one on which your program is running. both race to complete first. if the collector thread is able to download all data before your main thread hits second datareader then the accident is averted. but if the data is large or network is slow, or by sheer luck it didnt get enough cpu, then the main thread hits second datareader while the connection is still working.