[英]Bulk Operations with SQL CE / LINQ
I'm trying to write a program to convert a large amount of data from a legacy SQL Express system to a newer system based on SQL CE. 我正在尝试编写一个程序,以将大量数据从旧版SQL Express系统转换为基于SQL CE的较新系统。 Here's a quick snapshot of what's going on:
以下是发生的情况的快速快照:
For the smaller tables I can use LINQ just fine -- but the large table gives me problems. 对于较小的表,我可以使用LINQ很好-但是较大的表给我带来了问题。 The standard way of:
标准方式:
foreach(var dataRow in ...)
{
table.InsertOnSubmit(dataRow);
}
database.SubmitChanges();
Is painfully slow and takes several hours to complete. 非常缓慢,需要几个小时才能完成。 I've even tried doing some simple "bulk" operations to try and eliminate one giant insertion at the end of the loop, ie:
我什至尝试执行一些简单的“批量”操作来尝试消除循环末尾的一个巨大插入,即:
foreach(var dataRow in ...)
{
if(count == BULK_LIMIT)
{
count = 0;
database.SubmitChanges();
}
count++;
table.InsertOnSubmit(dataRow);
}
// Final submit, to catch the last BULK_LIMIT item block
database.SubmitChanges();
I've tried a variety of bulk sizes, from relatively small values like 1K-5K to larger sizes up to 300K. 我尝试了各种散装尺寸,从相对较小的值(如1K-5K)到较大的尺寸(最大为300K)。
Ultimately I'm stuck and the process takes roughly the same amount of time (several hours) regardless of the bulk size. 最终,我陷入了困境,无论批量大小如何,该过程花费的时间大致相同(几个小时)。
So - does anyone know of a way to crank up the speed? 所以-有人知道提高速度的方法吗? The typical solution would be to use SqlBulkCopy, but that isn't compatible with SQL CE.
典型的解决方案是使用SqlBulkCopy,但这与SQL CE不兼容。
A couple of notes: 一些注意事项:
Thanks in advance - all help is appreciated! 在此先感谢-感谢您的帮助!
-- Dan -丹
Use a parameterised INSERT statement: Prepare a command, set the parameter values in a loop and reuse the same command for each INSERT. 使用参数化的INSERT语句:准备命令,在循环中设置参数值,并对每个INSERT重用同一命令。
Remove any indexes and re-apply after you have performed all INSERTs. 执行所有INSERT后,请删除所有索引并重新应用。
Update : Chris Tacke has the fastest solution here using SqlCeResultset: Bulk Insert In SQLCE 更新 :Chris Tacke在这里使用SqlCeResultset具有最快的解决方案: SQLCE中的批量插入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.