The
SqlBulkCopy class provides a mechanism for efficiently importing
large amounts of data into a Microsoft SQL Server database. Compared to importing data by executing one INSERT statement for each record to import,
SqlBulkCopy is noticeably faster when importing thousands (or more) records. In a nutshell, importing data using SqlBulkCopy entails creating a
SqlBulkCopy object, specifying the destination database and table, and providing the data to import in the form of a DataTable, DataRow,
or DataReader. In
Using SqlBulkCopy To Perform Efficient Bulk SQL Operations we looked at how to use
SqlBulkCopy to programmatically import data from an uploaded Excel spreadsheet into a SQL Server database.
While
Using SqlBulkCopy To Perform Efficient Bulk SQL Operations showed how to use the SqlBulkCopy class, it did not explore how SqlBulkCopy
imports fare in the face of an error. What happens if, when importing a total of 10,000 records, an error occurs when importing record number 501? Should those first 500 records
be committed or should the entire batch be rolled back? This article examines the default behavior of the SqlBulkCopy class in the face of an error. It also
looks at how to perform bulk copy operations under the umbrella of a
transaction. Read on to learn more!
Note: If you have not yet read Using SqlBulkCopy To Perform Efficient Bulk SQL Operations, please
do so before reading this article...Read More >Source:
http://www.4guysfromrolla.com/articles/111109-1.aspx