I have a view in my database with around 200k entries. I'm reading it with the following code:
using (SqlConnection conn = new SqlConnection....)
{
conn.Open();
string query = "SELECT * FROM SP3DPROJECT.dbo.XSystemHierarchy";
using (SqlCommand comm = new SqlCommand())
{
comm.CommandText = query;
comm.Connection = conn;
using (SqlDataReader reader = comm.ExecuteReader())
{
DateTime start = DateTime.Now;
while (reader.Read())
{
// Code goes here, but for performance
// test I'm letting this empty
}
DateTime end = DateTime.Now;
TimeSpan elapsed = (end- start).TotalSeconds;
}
}
}
The view has only 2 columns of GUID
type. The ExecuteCommand()
is very fast, but the while loop (even with no code, just the looping) takes ~150 seconds.
Is there a better or fast way to do this?