In my windows service, I am executing a stored procedure that selects the top 2500 rows from a table and returns the data to the service. I am catching the results using the SqlDataReader
object.
My question is: does the SqlDataReader
object return the 2500 rows to my service and store them in memory at one time and read each record one by one or does it read each record one by one from the stored procedure in SQL Server?
Thank you!
SqlCommand getData = new SqlCommand(adminConnectionString, adminConnection);
// Sets SqlCommand Information
getData.CommandText = adminDatabaseName + ".dbo.SprocToExecute";
getData.CommandType = CommandType.StoredProcedure;
getData.CommandTimeout = 300;
// Creates parameters, sets their values, and adds them to the SqlCommand
SqlParameter sessionIDParameter = new SqlParameter("@SessionID", SqlDbType.Int);
sessionIDParameter.Value = ID;
getData.Parameters.Add(sessionIDParameter);
SqlDataReader dataReader = getData.ExecuteReader();
if (dataReader.HasRows)
{
while (dataReader.Read())
{
// DO SOMETHING WITH RECORD
}
}