When I call this code:
using (var connection = new SqlConnection(connectionString))
{
var command = new SqlCommand("SELECT * FROM Table", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while(reader.Read())
{
// Do something here
}
}
}
what happens internally? How does this work on a network level? Will it make a new round trip to database for each call to Read
or is there any batch read implemented internally?
I'm asking because I just read that ODP.NET provides FetchSize
property in both OracleCommand
and OracleDataReader
which I understand as definition of how many records should be preloaded by single round trip to the database. I wonder if SQL Server works in similar fashion and if there is some similar behavior which can be configured somewhere. I didn't find any such configuration in SqlCommand
, SqlDataReader
or CommandBehavior
.