Ejemplo n.º 1
0
        protected virtual void ImportDataReader(DbDataReader reader, TableInfo table, bool truncate)
        {
            using (var bulk = new SqlBulkCopy(cs))
            {
                bulk.BatchSize            = table.BatchSize;
                bulk.NotifyAfter          = table.BatchSize;
                bulk.DestinationTableName = table.DestTableName;

                foreach (var field in reader.Columns())
                {
                    bulk.ColumnMappings.Add(field, field);
                }

                try
                {
                    if (truncate)
                    {
                        Truncate(bulk.DestinationTableName);
                    }

                    bulk.WriteToServer(reader);
                }
                catch (Exception ex)
                {
                    OnImportError(table, ex);
                }
            }
        }