约45,000个数据检索存在以下问题。
当我使用DataReader.Read()调用每一行时,大约每15行就有一个延迟。
我试图通过链接解决问题,但失败了: Slow performance of SqlDataReader
下面是我要解决的问题的示例代码。
using (var reader = DbLib.SqlHelper.ExecuteReader(trans.Transaction, System.Data.CommandType.Text, query, parameters))
{
DateTime now = DateTime.Now;
while (reader.Read())
{
var item = new Item();
item.A= reader["A"] as string;
item.B= reader["B"] as string;
item.C= reader["C"] as string;
list.Add(item);
System.Diagnostics.Trace.WriteLine(DateTime.Now - now);
now = DateTime.Now;
}
}
//...
//00:00:00 <<- 1
//00:00:00.0009966 <<- 2
//00:00:00 <<- 3
//00:00:00 <<- 4
//00:00:00 <<- 5
//00:00:00 <<- 6
//00:00:00 <<- 7
//00:00:00 <<- 8
//00:00:00 <<- 9
//00:00:00 <<- 10
//00:00:00 <<- 11
//00:00:00 <<- 12
//00:00:00 <<- 13
//00:00:00 <<- 14
//00:00:01.5997433 <<- Delays occurs on the 15th line after the last dealy
//00:00:00 <<- 1
//00:00:00 <<- 2
//00:00:00 <<- 3
//00:00:00 <<- 4
//00:00:00 <<- 5
//00:00:00.0009984 <<- 6
//00:00:00 <<- 7
//00:00:00 <<- 8
//00:00:00 <<- 9
//00:00:00 <<- 10
//00:00:00 <<- 11
//00:00:00 <<- 12
//00:00:00.0009984 <<- 13
//00:00:00 <<- 14
//00:00:01.7323722 <<- Delays occurs on the 15th line after the last dealy
//00:00:00 <<- 1
//00:00:00 <<- 2
//00:00:00 <<- 3
//00:00:00 <<- 4
//00:00:00 <<- 5
//00:00:00 <<- 6
//00:00:00 <<- 7
//00:00:00 <<- 8
//00:00:00 <<- 9
//00:00:00 <<- 10
//00:00:00 <<- 11
//00:00:00 <<- 12
//00:00:00 <<- 13
//00:00:00 <<- 14
//00:00:00 <<- 15
//00:00:01.7014564 <<- Delays occurs on the 16th line after the last dealy
//...
在上面的代码中,System.TimeoutException最终将在循环期间发生,为了解决此问题,我想消除延迟的发生