MSDN class page

SqlBulkCopy is useful especially to import bulk data ( ~= 600,000, e.g.) records from a SQL or another source to a designated table in a SQL server.

BUT if you do this in a EntityFramework environment in .NET framework, then you might want to have this structure for faster performance.

// set db config properties to false to disable all the auto-detect and auto-validation
dbContext.Configuration.AutoDetectChangesEnabled = false;
dbContext.Configuration.ValidateOnSaveEnabled = false;

// perform bulk copy to SQL
using(SqlBulkCopy myCopy = SqlBulkCopy(sqlConnStr))

myCopy.BatchSize = 100; // row number to send to the server as a batch proc.
myCopy.WriteToServer(your data here);

// Re-set db configuration properties to true.
dbContext.Configuration.AutoDetectChangesEnabled = true;
dbContext.Configuration.ValidateOnSaveEnabled = true;

For details re how to use SqlBulkCopy, pls refer to the MSDN page link at the top of this article. Hope this helps. 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s