public Task ExecuteBulkCopyAsync(IDataReader source, ISqlBulkCopyParameters parameters, CancellationToken cancelToken) { throw new NotImplementedException(); }
public void ExecuteSqlBulkCopy(IDataReader dataReader, ISqlBulkCopyParameters bulkCopyParameters) { if (dataReader == null) { throw new ArgumentNullException(nameof(dataReader)); } if (bulkCopyParameters == null) { throw new ArgumentNullException(nameof(bulkCopyParameters)); } if (string.IsNullOrWhiteSpace(bulkCopyParameters.DestinationTableName)) { throw new ArgumentException(nameof(bulkCopyParameters.DestinationTableName), $"{nameof(bulkCopyParameters.DestinationTableName)} can't be null or whitespace."); } if (string.IsNullOrWhiteSpace(bulkCopyParameters.DestinationTableName)) { throw new ArgumentException(nameof(bulkCopyParameters.DestinationTableName), $"{nameof(bulkCopyParameters.DestinationTableName)} can't be null or whitespace."); } try { GetConnection(true); _sqlCommand = _sqlConnection.CreateCommand(); _sqlCommand.Connection = _sqlConnection; _sqlCommand.Transaction = _sqlTransaction; _sqlCommand.CommandTimeout = SqlCommand_DefaultTimeout; using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(_sqlConnection)) { if (bulkCopyParameters.BatchSize.HasValue) { sqlBulkCopy.BatchSize = bulkCopyParameters.BatchSize.Value; } if (bulkCopyParameters.Timeout.HasValue) { sqlBulkCopy.BulkCopyTimeout = bulkCopyParameters.Timeout.Value; } if (bulkCopyParameters.EnableStreaming.HasValue) { sqlBulkCopy.EnableStreaming = bulkCopyParameters.EnableStreaming.Value; } sqlBulkCopy.DestinationTableName = bulkCopyParameters.DestinationTableName; foreach (SqlBulkCopyColumnMapping columnMapping in bulkCopyParameters.ColumnMappings) { sqlBulkCopy.ColumnMappings.Add(columnMapping); } //todo: log executing sql //Perform bulk copy sqlBulkCopy.WriteToServer(dataReader); } } catch (Exception sqlException) { //todo: log error throw new DbContextHelperException(SqlExceptionMessage_SqlBulkCopy, sqlException); } finally { dataReader.Close(); ReleaseConnection(); } }
public void ExecuteSqlBulkCopy(IDataReader dataReader, ISqlBulkCopyParameters bulkCopyParameters) { throw new NotImplementedException(); }