public static void ExecuteBulkImport <T>(IEnumerable <T> records, string tableName) { OpenConnection(); using (var connection = _sqlConnection) { var bulkCopy = new SqlBulkCopy(connection); bulkCopy.DestinationTableName = tableName; var dataReader = new MyDataReader <T>(records.ToList()); try { bulkCopy.WriteToServer(dataReader); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } finally { CloseConnection(); } } }
public static void ExecuteBulkImport <T> (IEnumerable <T> records, string tableName) { OpenConnection(); using (SqlConnection connection = _sqlConnection) { SqlBulkCopy bc = new SqlBulkCopy(connection) { DestinationTableName = tableName }; var DataREader = new MyDataReader <T>(records.ToList()); try { bc.WriteToServer(DataREader); } catch { Console.WriteLine("Массовое копирование завершилось с ошибкой"); } finally { CloseConnection(); } } }