加载非常大的CSV文件为s的SQL Server数据库 [英] Load very big CSV-Files into s SQL-Server database
本文介绍了加载非常大的CSV文件为s的SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种高性能的方式来加载非常大的CSV文件(其中有几千兆字节大小)到一个SQL Server 2008数据库与.NET?
Is there a performant way to load very big CSV-files (which have size of several gigabytes) into an SQL-Server 2008 database with .NET?
推荐答案
我将结合的这个CSV阅读器与 SqlBulkCopy的
;即。
I would combine this CSV reader with SqlBulkCopy
; i.e.
using (var file = new StreamReader(path))
using (var csv = new CsvReader(file, true)) // true = has header row
using (var bcp = new SqlBulkCopy(connection)) {
bcp.DestinationTableName = "TableName";
bcp.WriteToServer(csv);
}
本使用大容量复制API做的插入,同时采用了全管理(和快速)的IDataReader
执行(关键的是,它的流的数据,而不是加载一次全部)。
This uses the bulk-copy API to do the inserts, while using a fully-managed (and fast) IDataReader
implementation (crucially, which streams the data, rather than loading it all at once).
这篇关于加载非常大的CSV文件为s的SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文