예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="reader"></param>
        public void BulkCopy(SqlBulkCopyContext context, IDataReader reader)
        {
            var            dr        = reader;
            var            state     = ConnectionState;
            DateTimeOffset?startTime = null;
            DateTimeOffset?endTime   = null;

            if (context.Connection == null)
            {
                if (this.ConnectionString != context.ConnectionString)
                {
                    throw new InvalidOperationException();
                }
            }
            else
            {
                if (this.Connection != context.Connection)
                {
                    throw new InvalidOperationException();
                }
            }
            if (context.Transaction != null && this.Transaction != context.Transaction)
            {
                throw new InvalidOperationException();
            }

            try
            {
                var e = SqlServerDatabase.OnCommandExecuting(new CommandExecutingEventArgs(MethodName.BulkCopy, ConnectionString, context));
                if (e != null && e.Cancel == true)
                {
                    return;
                }

                Open();
                var bc = context.SqlBulkCopy;
                startTime = DateTimeOffset.Now;
                bc.WriteToServer(dr);
                endTime = DateTimeOffset.Now;
                dr.Close();
            }
            catch (Exception exception)
            {
                this.CatchException(MethodName.BulkCopy, this.ConnectionString, context, exception);
            }
            finally
            {
                if (state == ConnectionState.Closed)
                {
                    this.Close();
                }
                ((IDisposable)context.SqlBulkCopy).Dispose();
            }
            if (startTime.HasValue == true && endTime.HasValue == true)
            {
                SqlServerDatabase.OnCommandExecuted(new CommandExecutedEventArgs(MethodName.BulkCopy, this.ConnectionString, startTime.Value, endTime.Value, context));
            }
        }
예제 #2
0
        private void CatchException(MethodName methodName, String connectionString, SqlBulkCopyContext context, Exception exception)
        {
            var e = new CommandErrorEventArgs(methodName, connectionString, exception, context);

            SqlServerDatabase.OnCommandError(e);
            if (e.ThrowException == true)
            {
                var ex = CreateException(e);
            }
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="context"></param>
 public CommandExecutingEventArgs(MethodName methodName, String connectionString, SqlBulkCopyContext sqlBulkCopyContext)
     : this(methodName, connectionString)
 {
     Cancel = false;
     this.SqlBulkCopyContext = sqlBulkCopyContext;
 }
 public SqlServerCommandErrorEventArgs(MethodName methodName, String connectionString, Exception exception, Object executionContext, SqlBulkCopyContext sqlBulkCopyContext)
     : base(methodName, connectionString, exception, executionContext)
 {
     this.SqlBulkCopyContext = sqlBulkCopyContext;
 }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="context"></param>
 public CommandExecutedEventArgs(MethodName methodName, String connectionString, DateTimeOffset startTime, DateTimeOffset endTime, Object executionContext, SqlBulkCopyContext sqlBulkCopyContext)
     : this(methodName, connectionString, startTime, endTime, executionContext)
 {
     this.Context = sqlBulkCopyContext;
 }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="context"></param>
 /// <param name="exception"></param>
 public CommandErrorEventArgs(MethodName methodName, String connectionString, Exception exception, SqlBulkCopyContext context)
     : this(methodName, connectionString, exception)
 {
     this.Context = context;
 }