Different ways of Handling Bulk Inserts using C# and SQL Server
When we need to insert bulk data into sql database through application we have different options to do so. Bulk data can be like 10k records or 100k records or even more. We need to keep the amount of time it takes to insert data as minimal as possible. Otherwise it will hit the performance of the application. The below are the different ways of doing the bulk inserts. 1) SqlBulkCopy (Available from ASP.Net 2.0) 2) Table Valued Parameters (Available from SQL Server 2008+) 3) Short Hand Insert Query Execution time Comparison with 50K Records Insertion: 1) SqlBulkCopy: It is a class which enables you to send bulk data to Sql Server table. You can send the data using DataTable. You can use WriteToServer() method to make a request to sql server for bulkinsert. While the bulk copy operation is in progress, the associated destination SqlConnection is busy serving it, and no other operations can be performed on the connection. Sample Code: In this example I ...