SqlDataReader is slow
Hi Folks,
I have a typical situation here.
My application is a sequence of windows jobs (all are coded in C#).
Now one of my jobs when run is supposed to fetch around 100,000 records from the SQLDataReader, the SP returns 100,000 records. So, this SP call from C# and then reading the data using DataReader are happening on one method say its "myMyMethod()". Every other part of the application is fast than the part where I am trying to read the data from the DataReader, it takes 20 min to read the data. I have the time printed before the start of reading data from the DataReader and immediately after I am done with reading data from the DataReader (that is how I know that it takes roughly 20 min).
Now I am doing all that stuff that I need to do to have the DataReader behave fast like, I am using (this is inside myMyMethod()" ) :
while (dataReader.Read())
{
.....
object[] myObjectArray = new object[dataReader.FiledCount];
dataReader.GetValues(myObjectArray);
//Now read each value and cast it to the right type and assign it to the
// valueObject.
myLongVal = (long)myObjectArray[0];
myStringVal = (string)myObjectArray[1];
.......
myObjectArray = null;
}
Now after this job is done (which takes rougly 20 min).
Now I will start running my next job, which calls the same "myMyMethod()" which I said above. This job also is suppose to get almost the same amount of data as my Job-1 did. But now the same method runs in just 2 min (as opposed to 20 min in my previous job).
If I somehow manipulate my data in the DB and run my job-2 first then again the "myMyMethod()", it takes 20 min now.
I am just confused...can somebody help me. I have checked there is no memory leak or anything. I dont why the same SP call and the same DataReader is taking more time first time and second time it runs fast...
Thanks in advance.
Have a nice day.
Regards,
Kris

