SqlBulkCopy The fastest way to insert your data into SQL Server.

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString, transaction))
{
 // SET BatchSize value.
 bulkCopy.BatchSize = 4000;

 bulkCopy.DestinationTableName = "TheDestinationTable";
 bulkCopy.WriteToServer(dt);
}



What's SqlBulkCopy?

SqlBulkCopy is a Microsoft class that let you to efficiently bulk insert data to SQL Server table. That is the fastest way to insert multiples rows.



How can I improve SqlBulkCopy performance?

It's possible to improve SqlBulkCopy performance by specifying a batch size (not too low, not too high!) and locking the table using SqlBulkCopyOptions.



What are commons SqlBulkCopy exception?

Here is a list of common SqlBulkCopy exceptions:



How to retrieve identity values with SqlBulkCopy?

You cannot, but a third-party library does: Bulk Operations. It's a prime library that overcome SqlBulkCopy limitations.

Learn More


How to Bulk Update with SqlBulkCopy?

You cannot, but a third-party library does: Bulk Operations. It's a prime library that support all bulk operations:

  • Bulk Insert
  • Bulk Update
  • Bulk Delete
  • Bulk Merge
Learn More


Which provider SqlBulkCopy support?

It support SQL Server & SQL Azure. However more provide can be supported via Bulk Operations. It's a prime library that support all major providers:

  • SQL Server 2008+
  • SQL Azure
  • SQL Compact
  • MySQL
  • SQLite
  • PostgreSQL
  • Oracle
Learn More