public string BulkInsert(DataTable dt, bool IsPurgeData) { string Message = string.Empty; using (SqlConnection connection = new SqlConnection(this.CurrentClient.ApplicationDBConnectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); } //Creating Transaction so that it can rollback if got any error while uploading SqlTransaction trans = connection.BeginTransaction(); //Start bulkCopy using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.FireTriggers, trans)) { //Setting timeout to 0 means no time out for this command will not timeout until upload complete. //Change as per you bulkCopy.BulkCopyTimeout = 0; bulkCopy.ColumnMappings.Add("InputId", "InputId"); bulkCopy.ColumnMappings.Add("SrcRecordId", "SrcRecordId"); bulkCopy.DestinationTableName = "ext.StgImportDataForRejectPurge"; try { bulkCopy.WriteToServer(dt); trans.Commit(); SettingFacade sfac = new SettingFacade(this.CurrentClient.ApplicationDBConnectionString); Message = sfac.RejectPurgeDataFromImport(Helper.oUser.UserId, IsPurgeData); } catch (Exception ex) { Message = ex.Message.ToString(); } } } return(Message); }