简体   繁体   中英

What is the fastest way to save data in SQL Server using C#?

I am currently working on a small .NET app in C#, that fetches data through some web service.

The data is represented in objects, so it would have been logical to store the data in a document based database, but there is a demand to use SQL Server.

So what might be the fastest way to insert many thousands, perhaps millions of rows into a database.

I an open to any framework, that might could support that, but I haven't been able to find any benchmarking on this eg on Entity Framework.

To iterate over the data an do an insert per row is simply to slow, then it would be quicker to dump the data in a file, and then do a bulk import using SSIS, but for this scenario I would rather avoid that, and keep all logic in the C# app.

You might want to use the SqlBulkCopy class. It is quite efficient for large data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM