/*public OdbcCommand CreateCommand() { // MDAC 68309
         *  OdbcCommand cmd = Connection.CreateCommand();
         *  cmd.Transaction = this;
         *  return cmd;
         * }
         *
         * IDbCommand IDbTransaction.CreateCommand() {
         *  return CreateCommand();
         * }*/

        /// <include file='doc\OdbcTransaction.uex' path='docs/doc[@for="OdbcTransaction.Commit"]/*' />
        public void Commit()
        {
            OdbcConnection.OdbcPermission.Demand(); // MDAC 81476

            if (null == this.connection)
            {
                throw ADP.TransactionZombied(this);
            }
            connection.CheckState(ADP.CommitTransaction); // MDAC 68289

            //Note: SQLEndTran success if not actually in a transaction, so we have to throw
            //since the IDbTransaciton spec indicates this is an error for the managed packages
            if (AutoCommit)
            {
                throw ODC.NotInTransaction();
            }

            //Commit the transaction (for just this connection)
            ODBC32.RETCODE retcode = (ODBC32.RETCODE)
                                     UnsafeNativeMethods.Odbc32.SQLEndTran(
                (short)ODBC32.SQL_HANDLE.DBC,
                this.connection._dbcWrapper,
                (Int16)ODBC32.SQL_TXN.COMMIT);
            if (retcode != ODBC32.RETCODE.SUCCESS)
            {
                this.connection.HandleError(this.connection._dbcWrapper, ODBC32.SQL_HANDLE.DBC, retcode);
            }

            //Transaction is complete...
            AutoCommit = true;
            this.connection.weakTransaction = null;
            this.connection._dbcWrapper._isInTransaction = false;
            this.connection = null;
        }
Esempio n. 2
0
        public override void Commit()
        {
            OdbcConnection connection = _connection;

            if (null == connection)
            {
                throw ADP.TransactionZombied(this);
            }

            connection.CheckState(ADP.CommitTransaction); // MDAC 68289

            //Note: SQLEndTran success if not actually in a transaction, so we have to throw
            //since the IDbTransaciton spec indicates this is an error for the managed packages
            if (null == _handle)
            {
                throw ODBC.NotInTransaction();
            }

            ODBC32.RetCode retcode = _handle.CompleteTransaction(ODBC32.SQL_COMMIT);
            if (retcode == ODBC32.RetCode.ERROR)
            {
                //If an error has occurred, we will throw an exception in HandleError,
                //and leave the transaction active for the user to retry
                connection.HandleError(_handle, retcode);
            }

            //Transaction is complete...
            connection.LocalTransaction = null;
            _connection = null;
            _handle     = null;
        }
Esempio n. 3
0
        public override void Rollback()
        {
            OdbcConnection connection = this._connection;

            if (connection == null)
            {
                throw ADP.TransactionZombied(this);
            }
            connection.CheckState("RollbackTransaction");
            if (this._handle == null)
            {
                throw ODBC.NotInTransaction();
            }
            ODBC32.RetCode retcode = this._handle.CompleteTransaction(1);
            if (retcode == ODBC32.RetCode.ERROR)
            {
                connection.HandleError(this._handle, retcode);
            }
            connection.LocalTransaction = null;
            this._connection            = null;
            this._handle = null;
        }
Esempio n. 4
0
        public override void Commit()
        {
            OdbcConnection.ExecutePermission.Demand();
            OdbcConnection connection = this._connection;

            if (connection == null)
            {
                throw ADP.TransactionZombied(this);
            }
            connection.CheckState("CommitTransaction");
            if (this._handle == null)
            {
                throw ODBC.NotInTransaction();
            }
            ODBC32.RetCode retcode = this._handle.CompleteTransaction(0);
            if (retcode == ODBC32.RetCode.ERROR)
            {
                connection.HandleError(this._handle, retcode);
            }
            connection.LocalTransaction = null;
            this._connection            = null;
            this._handle = null;
        }