Exemplo n.º 1
0
        public DisabledForeignKeyCheckContext(SqlTransactionalCommandsContext context)
        {
            var command = ((DefaultSqlTransactionalCommandsContext)context).DbConnection.CreateCommand();

            command.CommandText = "SET CONSTRAINTS ALL DEFERRED;";
            command.ExecuteNonQuery();
        }
Exemplo n.º 2
0
        public DisabledForeignKeyCheckContext(SqlTransactionalCommandsContext context)
        {
            this.context = context;

            var command = ((DefaultSqlTransactionalCommandsContext)context).DbConnection.CreateCommand();

            // LogicalNot Azure compatible - command.CommandText = "EXEC sp_msforeachtable \"ALTER TABLE ? NOCHECK CONSTRAINT all\"";

            command.CommandText =
                @"DECLARE @table_name SYSNAME;
DECLARE @cmd NVARCHAR(MAX);
DECLARE table_cursor CURSOR FOR SELECT name FROM sys.tables;

OPEN table_cursor;
FETCH NEXT FROM table_cursor INTO @table_name;

WHILE @@FETCH_STATUS = 0 BEGIN
  SELECT @cmd = 'ALTER TABLE '+QUOTENAME(@table_name)+' NOCHECK CONSTRAINT ALL';
  EXEC (@cmd);
  FETCH NEXT FROM table_cursor INTO @table_name;
END

CLOSE table_cursor;
DEALLOCATE table_cursor;";

            command.ExecuteNonQuery();
        }
        public DisabledForeignKeyCheckContext(SqlTransactionalCommandsContext context)
        {
            this.context = context;

            var command = ((DefaultSqlTransactionalCommandsContext)context).DbConnection.CreateCommand();

            command.CommandText = "SET FOREIGN_KEY_CHECKS = 0;";

            command.ExecuteNonQuery();
        }
        public DisabledForeignKeyCheckContext(SqlTransactionalCommandsContext context)
        {
            this.context = context;

            using (var command = ((DefaultSqlTransactionalCommandsContext)context).CreateCommand())
            {
                command.CommandText = "PRAGMA foriegn_keys = OFF;";

                command.ExecuteNonQuery();
            }
        }
Exemplo n.º 5
0
 public override IDisabledForeignKeyCheckContext AcquireDisabledForeignKeyCheckContext(SqlTransactionalCommandsContext sqlDatabaseCommandsContext)
 {
     return(new DisabledForeignKeyCheckContext(sqlDatabaseCommandsContext));
 }
 public DisabledForeignKeyCheckContext(SqlTransactionalCommandsContext context)
 {
 }
Exemplo n.º 7
0
		public virtual void Prepare(PreparingEnlistment preparingEnlistment)
		{
			if (this.disposed)
			{
				return;
			}

			var dispose = true;

			try
			{
				if (this.dataAccessObjectDataContext != null)
				{
					this.commandsContext = this.GetSqlTransactionalCommandsContext();
					this.dataAccessObjectDataContext.Commit(this.commandsContext, false);

					if (this.commandsContext.SqlDatabaseContext.SupportsPreparedTransactions)
					{
						this.commandsContext.Prepare();
					}
				}

				preparingEnlistment.Prepared();

				dispose = false;
			}
			catch (TransactionAbortedException)
			{
				throw;
			}
			catch (Exception e)
			{
				ActionUtils.IgnoreExceptions(() => this.commandsContext?.Rollback());

				preparingEnlistment.ForceRollback(e);
			}
			finally
			{
				if (dispose)
				{
					this.Dispose();
				}
			}
		}
Exemplo n.º 8
0
		public void Commit()
		{
			if (this.disposed)
			{
				return;
			}

			try
			{
				if (this.dataAccessObjectDataContext != null)
				{
					this.commandsContext = this.GetSqlTransactionalCommandsContext();
					this.dataAccessObjectDataContext.Commit(this.commandsContext, false);
					this.commandsContext.Commit();
				}
			}
			catch (Exception e)
			{
				ActionUtils.IgnoreExceptions(() => this.commandsContext?.Rollback());

				throw new DataAccessTransactionAbortedException(e);
			}
			finally
			{
				this.Dispose();
			}
		}
Exemplo n.º 9
0
		public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
		{
			if (this.disposed)
			{
				return;
			}

			try
			{
				if (this.dataAccessObjectDataContext != null)
				{
					this.commandsContext = this.GetSqlTransactionalCommandsContext();

					this.dataAccessObjectDataContext.Commit(this.commandsContext, false);
					this.commandsContext.Commit();
				}

				singlePhaseEnlistment.Committed();
			}
			catch (Exception e)
			{
				ActionUtils.IgnoreExceptions(() => this.commandsContext.Rollback());

				singlePhaseEnlistment.Aborted(e);
			}
			finally
			{
				this.Dispose();
			}
		}
Exemplo n.º 10
0
		public virtual SqlTransactionalCommandsContext GetSqlTransactionalCommandsContext()
		{
			if (this.disposed)
			{
				throw new ObjectDisposedException(nameof(TransactionContext));
			}

			return this.commandsContext ?? (this.commandsContext = this.GetSqlDatabaseContext().CreateSqlTransactionalCommandsContext(this));
		}
 public DatabaseTransactionContextAcquisition(TransactionContext transactionContext, SqlDatabaseContext sqlDatabaseContext, SqlTransactionalCommandsContext sqlDatabaseCommandsContext)
 {
     this.TransactionContext = transactionContext;
     this.SqlDatabaseContext = sqlDatabaseContext;
     this.SqlDatabaseCommandsContext = sqlDatabaseCommandsContext;
 }
Exemplo n.º 12
0
 public TransactionEntry(SqlTransactionalCommandsContext value)
 {
     this.sqlDatabaseCommandsContext = value;
 }