How to speed up reading large amounts of data in SQL Server and C# -


i have view in database around 200k entries. i'm reading following code:

using (sqlconnection conn = new sqlconnection....) {     conn.open();      string query = "select * 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, performance                  // test i'm letting empty             }              datetime end = datetime.now;             timespan elapsed = (end- start).totalseconds;         }     } } 

the view has 2 columns of guid type. executecommand() fast, while loop (even no code, looping) takes ~150 seconds.

is there better or fast way this?

try using load method on datatable. faster.

example:

datatable dt = new datatable(); dt.load(cmd.executereader()); return dt; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -