The following simple code retrieve data with SqlDataReader:
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=myDB;Integrated Security=True");
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT [t0].[ID], [t0].[Name] FROM [Persons] AS [t0]";
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine(rdr["id"] + " " + rdr["name"]);
}
While the code is running, I use Sql Profiler to monitor the DB. And I saw only one select command.
SELECT [t0].[ID], [t0].[Name] FROM [Persons] AS [t0]
So it seems the SqlDataReader will retrieve ALL the data from server first, and then enumerate them.
Is that true? What if the data is too many?