[英]C# DbDataReader populating List result in OutOfMemoryException
I am currently trying to read a large table from an compact ce database containing aprox 3-4 million rows. 我目前正在尝试从一个紧凑的ce数据库中读取一个大表,该数据库包含aprox 3-4百万行。 The database size i currently 832MB. 我当前的数据库大小为832MB。 Populating a list with the records is throwing OutOfMemoryException
用记录OutOfMemoryException
列表会OutOfMemoryException
The mockup code: 样机代码:
using (var con = new DomainContext())
{
foreach (var item in con.logRecords)
{
if (item.Info != null && item.Info != "")
item.Timestamp = DateTime.ParseExact(item.Info, "MM.dd.yyyy HH:mm:ss.fff", culture).Ticks;
}
con.SaveChanges();
}
New approach, still not getting it to work.... 新方法,仍然无法正常工作。
Task.Factory.StartNew(() =>
{
using (var con = new DomainContext())
{
for (int i = 0; i < 300; i++)
{
try
{
var temp = con.logRecords.Where(p => p.Id <= i * 10000 + 10000 && p.Id >= i * 10000);
foreach (var item in temp)
{
if (item.Info != null && item.Info != "")
item.Timestamp = DateTime.ParseExact(item.Info, "MM.dd.yyyy HH:mm:ss.fff", culture).Ticks;
}
con.SaveChanges();
}
catch { }
GC.Collect();
Console.WriteLine(i.ToString());
}
}
});
I used native SQL, parsed timestamp to SQL timestamp then found number off seconds since 1970 using DATEDIFF ( datepart , startdate , enddate ). 我使用本机SQL,将时间戳解析为SQL时间戳,然后使用DATEDIFF(datepart,startdate,enddate)找到自1970年以来的秒数。 Added number of seconds since year 0. I lose millisecond part, but i guess this is the next best thing. 从0年起增加了秒数。我损失了毫秒部分,但是我想这是下一件最好的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.