Beispiel #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         SNIHandle target = null;
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             target = SqlInternalConnection.GetBestEffortCleanupTarget(this._connection);
             if (!this.IsZombied && !this.IsYukonPartialZombie)
             {
                 this._internalTransaction.Dispose();
             }
         }
         catch (OutOfMemoryException exception3)
         {
             this._connection.Abort(exception3);
             throw;
         }
         catch (StackOverflowException exception2)
         {
             this._connection.Abort(exception2);
             throw;
         }
         catch (ThreadAbortException exception)
         {
             this._connection.Abort(exception);
             SqlInternalConnection.BestEffortCleanup(target);
             throw;
         }
     }
     base.Dispose(disposing);
 }
Beispiel #2
0
 public override void ChangeDatabase(string database)
 {
     SNIHandle target = null;
     SqlStatistics statistics = null;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         target = SqlInternalConnection.GetBestEffortCleanupTarget(this);
         statistics = SqlStatistics.StartTimer(this.Statistics);
         this.InnerConnection.ChangeDatabase(database);
     }
     catch (OutOfMemoryException exception3)
     {
         this.Abort(exception3);
         throw;
     }
     catch (StackOverflowException exception2)
     {
         this.Abort(exception2);
         throw;
     }
     catch (ThreadAbortException exception)
     {
         this.Abort(exception);
         SqlInternalConnection.BestEffortCleanup(target);
         throw;
     }
     finally
     {
         SqlStatistics.StopTimer(statistics);
     }
 }
        ////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        ////////////////////////////////////////////////////////////////////////////////////////

        override public void Commit()
        {
            SqlConnection.ExecutePermission.Demand(); // MDAC 81476

            ZombieCheck();

            SqlStatistics statistics = null;
            IntPtr        hscp;

            Bid.ScopeEnter(out hscp, "<sc.SqlTransaction.Commit|API> %d#", ObjectID);
            Bid.CorrelationTrace("<sc.SqlTransaction.Commit|API|Correlation> ObjectID%d#, ActivityID %ls", ObjectID);

            TdsParser bestEffortCleanupTarget = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
#if DEBUG
                TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();

                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    tdsReliabilitySection.Start();
#else
                {
#endif //DEBUG
                    bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(_connection);
                    statistics = SqlStatistics.StartTimer(Statistics);

                    _isFromAPI = true;

                    _internalTransaction.Commit();
                }
#if DEBUG
                finally {
                    tdsReliabilitySection.Stop();
                }
#endif //DEBUG
            }
            catch (System.OutOfMemoryException e) {
                _connection.Abort(e);
                throw;
            }
            catch (System.StackOverflowException e) {
                _connection.Abort(e);
                throw;
            }
            catch (System.Threading.ThreadAbortException e)  {
                _connection.Abort(e);
                SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
                throw;
            }
            finally {
                _isFromAPI = false;

                SqlStatistics.StopTimer(statistics);
                Bid.ScopeLeave(ref hscp);
            }
        }
Beispiel #4
0
 public override void Close()
 {
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<sc.SqlConnection.Close|API> %d#", this.ObjectID);
     try
     {
         SqlStatistics statistics = null;
         SNIHandle target = null;
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             target = SqlInternalConnection.GetBestEffortCleanupTarget(this);
             statistics = SqlStatistics.StartTimer(this.Statistics);
             lock (this.InnerConnection)
             {
                 this.InnerConnection.CloseConnection(this, this.ConnectionFactory);
             }
             if (this.Statistics != null)
             {
                 ADP.TimerCurrent(out this._statistics._closeTimestamp);
             }
         }
         catch (OutOfMemoryException exception3)
         {
             this.Abort(exception3);
             throw;
         }
         catch (StackOverflowException exception2)
         {
             this.Abort(exception2);
             throw;
         }
         catch (ThreadAbortException exception)
         {
             this.Abort(exception);
             SqlInternalConnection.BestEffortCleanup(target);
             throw;
         }
         finally
         {
             SqlStatistics.StopTimer(statistics);
         }
     }
     finally
     {
         SqlDebugContext context = this._sdc;
         this._sdc = null;
         Bid.ScopeLeave(ref ptr);
         if (context != null)
         {
             context.Dispose();
         }
     }
 }
Beispiel #5
0
        static public void DeriveParameters(SqlCommand command)   // MDAC 65927\
        {
            SqlConnection.ExecutePermission.Demand();

            if (null == command)
            {
                throw ADP.ArgumentNull("command");
            }
            TdsParser bestEffortCleanupTarget = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
#if DEBUG
                TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();

                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    tdsReliabilitySection.Start();
#else
                {
#endif
                    bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(command.Connection);
                    command.DeriveParameters();
                }
#if DEBUG
                finally {
                    tdsReliabilitySection.Stop();
                }
#endif
            }
            catch (System.OutOfMemoryException e) {
                if (null != command && null != command.Connection)
                {
                    command.Connection.Abort(e);
                }
                throw;
            }
            catch (System.StackOverflowException e) {
                if (null != command && null != command.Connection)
                {
                    command.Connection.Abort(e);
                }
                throw;
            }
            catch (System.Threading.ThreadAbortException e)  {
                if (null != command && null != command.Connection)
                {
                    command.Connection.Abort(e);
                }
                SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
                throw;
            }
        }
Beispiel #6
0
 public override void Rollback()
 {
     if (this.IsYukonPartialZombie)
     {
         if (Bid.AdvancedOn)
         {
             Bid.Trace("<sc.SqlTransaction.Rollback|ADV> %d# partial zombie no rollback required\n", this.ObjectID);
         }
         this._internalTransaction = null;
     }
     else
     {
         IntPtr ptr;
         this.ZombieCheck();
         SqlStatistics statistics = null;
         Bid.ScopeEnter(out ptr, "<sc.SqlTransaction.Rollback|API> %d#", this.ObjectID);
         SNIHandle target = null;
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             target          = SqlInternalConnection.GetBestEffortCleanupTarget(this._connection);
             statistics      = SqlStatistics.StartTimer(this.Statistics);
             this._isFromAPI = true;
             this._internalTransaction.Rollback();
         }
         catch (OutOfMemoryException exception3)
         {
             this._connection.Abort(exception3);
             throw;
         }
         catch (StackOverflowException exception2)
         {
             this._connection.Abort(exception2);
             throw;
         }
         catch (ThreadAbortException exception)
         {
             this._connection.Abort(exception);
             SqlInternalConnection.BestEffortCleanup(target);
             throw;
         }
         finally
         {
             this._isFromAPI = false;
             SqlStatistics.StopTimer(statistics);
             Bid.ScopeLeave(ref ptr);
         }
     }
 }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                TdsParser bestEffortCleanupTarget = null;
                RuntimeHelpers.PrepareConstrainedRegions();
                try {
#if DEBUG
                    TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();

                    RuntimeHelpers.PrepareConstrainedRegions();
                    try {
                        tdsReliabilitySection.Start();
#else
                    {
#endif //DEBUG
                        bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(_connection);
                        if (!IsZombied && !IsYukonPartialZombie)
                        {
                            _internalTransaction.Dispose();
                        }
                    }
#if DEBUG
                    finally {
                        tdsReliabilitySection.Stop();
                    }
#endif //DEBUG
                }
                catch (System.OutOfMemoryException e) {
                    _connection.Abort(e);
                    throw;
                }
                catch (System.StackOverflowException e) {
                    _connection.Abort(e);
                    throw;
                }
                catch (System.Threading.ThreadAbortException e)  {
                    _connection.Abort(e);
                    SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
                    throw;
                }
            }
            base.Dispose(disposing);
        }
Beispiel #8
0
        public override void Commit()
        {
            IntPtr ptr;

            SqlConnection.ExecutePermission.Demand();
            this.ZombieCheck();
            SqlStatistics statistics = null;

            Bid.ScopeEnter(out ptr, "<sc.SqlTransaction.Commit|API> %d#", this.ObjectID);
            SNIHandle target = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                target          = SqlInternalConnection.GetBestEffortCleanupTarget(this._connection);
                statistics      = SqlStatistics.StartTimer(this.Statistics);
                this._isFromAPI = true;
                this._internalTransaction.Commit();
            }
            catch (OutOfMemoryException exception3)
            {
                this._connection.Abort(exception3);
                throw;
            }
            catch (StackOverflowException exception2)
            {
                this._connection.Abort(exception2);
                throw;
            }
            catch (ThreadAbortException exception)
            {
                this._connection.Abort(exception);
                SqlInternalConnection.BestEffortCleanup(target);
                throw;
            }
            finally
            {
                this._isFromAPI = false;
                SqlStatistics.StopTimer(statistics);
                Bid.ScopeLeave(ref ptr);
            }
        }
        public static void DeriveParameters(SqlCommand command)
        {
            SqlConnection.ExecutePermission.Demand();
            if (command == null)
            {
                throw ADP.ArgumentNull("command");
            }
            SNIHandle target = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                target = SqlInternalConnection.GetBestEffortCleanupTarget(command.Connection);
                command.DeriveParameters();
            }
            catch (OutOfMemoryException exception3)
            {
                if ((command != null) && (command.Connection != null))
                {
                    command.Connection.Abort(exception3);
                }
                throw;
            }
            catch (StackOverflowException exception2)
            {
                if ((command != null) && (command.Connection != null))
                {
                    command.Connection.Abort(exception2);
                }
                throw;
            }
            catch (ThreadAbortException exception)
            {
                if ((command != null) && (command.Connection != null))
                {
                    command.Connection.Abort(exception);
                }
                SqlInternalConnection.BestEffortCleanup(target);
                throw;
            }
        }
Beispiel #10
0
        override public void EnlistTransaction(SysTx.Transaction transaction)
        {
            SqlConnection.VerifyExecutePermission();

            ValidateConnectionForExecute(null);

            // If a connection has a local transaction outstanding and you try
            // to enlist in a DTC transaction, SQL Server will rollback the
            // local transaction and then do the enlist (7.0 and 2000).  So, if
            // the user tries to do this, throw.
            if (HasLocalTransaction)
            {
                throw ADP.LocalTransactionPresent();
            }

            if (null != transaction && transaction.Equals(EnlistedTransaction))
            {
                // No-op if this is the current transaction
                return;
            }

            // If a connection is already enlisted in a DTC transaction and you
            // try to enlist in another one, in 7.0 the existing DTC transaction
            // would roll back and then the connection would enlist in the new
            // one. In SQL 2000 & Yukon, when you enlist in a DTC transaction
            // while the connection is already enlisted in a DTC transaction,
            // the connection simply switches enlistments.  Regardless, simply
            // enlist in the user specified distributed transaction.  This
            // behavior matches OLEDB and ODBC.

            TdsParser bestEffortCleanupTarget = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
#if DEBUG
                TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();

                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    tdsReliabilitySection.Start();
#else
                {
#endif //DEBUG
                    bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(Connection);
                    Enlist(transaction);
                }
#if DEBUG
                finally {
                    tdsReliabilitySection.Stop();
                }
#endif //DEBUG
            }
            catch (System.OutOfMemoryException e) {
                Connection.Abort(e);
                throw;
            }
            catch (System.StackOverflowException e) {
                Connection.Abort(e);
                throw;
            }
            catch (System.Threading.ThreadAbortException e) {
                Connection.Abort(e);
                SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
                throw;
            }
        }
Beispiel #11
0
        override protected void Deactivate()
        {
            if (Bid.AdvancedOn)
            {
                Bid.Trace("<sc.SqlInternalConnection.Deactivate|ADV> %d# deactivating\n", base.ObjectID);
            }
            TdsParser bestEffortCleanupTarget = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
#if DEBUG
                TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();

                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    tdsReliabilitySection.Start();
#else
                {
#endif //DEBUG
                    bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(Connection);
                    SqlReferenceCollection referenceCollection = (SqlReferenceCollection)ReferenceCollection;
                    if (null != referenceCollection)
                    {
                        referenceCollection.Deactivate();
                    }

                    // Invoke subclass-specific deactivation logic
                    InternalDeactivate();
                }
#if DEBUG
                finally {
                    tdsReliabilitySection.Stop();
                }
#endif //DEBUG
            }
            catch (System.OutOfMemoryException) {
                DoomThisConnection();
                throw;
            }
            catch (System.StackOverflowException) {
                DoomThisConnection();
                throw;
            }
            catch (System.Threading.ThreadAbortException) {
                DoomThisConnection();
                SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
                throw;
            }
            catch (Exception e) {
                //
                if (!ADP.IsCatchableExceptionType(e))
                {
                    throw;
                }

                // if an exception occurred, the inner connection will be
                // marked as unusable and destroyed upon returning to the
                // pool
                DoomThisConnection();

                ADP.TraceExceptionWithoutRethrow(e);
            }
        }
Beispiel #12
0
        virtual internal SqlTransaction BeginSqlTransaction(IsolationLevel iso, string transactionName, bool shouldReconnect)
        {
            SqlStatistics statistics = null;
            TdsParser     bestEffortCleanupTarget = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
#if DEBUG
                TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();

                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    tdsReliabilitySection.Start();
#else
                {
#endif //DEBUG
                    bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(Connection);
                    statistics = SqlStatistics.StartTimer(Connection.Statistics);

                    SqlConnection.ExecutePermission.Demand(); // MDAC 81476

                    ValidateConnectionForExecute(null);

                    if (HasLocalTransactionFromAPI)
                    {
                        throw ADP.ParallelTransactionsNotSupported(Connection);
                    }

                    if (iso == IsolationLevel.Unspecified)
                    {
                        iso = IsolationLevel.ReadCommitted; // Default to ReadCommitted if unspecified.
                    }

                    SqlTransaction transaction = new SqlTransaction(this, Connection, iso, AvailableInternalTransaction);
                    transaction.InternalTransaction.RestoreBrokenConnection = shouldReconnect;
                    ExecuteTransaction(TransactionRequest.Begin, transactionName, iso, transaction.InternalTransaction, false);
                    transaction.InternalTransaction.RestoreBrokenConnection = false;
                    return(transaction);
                }
#if DEBUG
                finally {
                    tdsReliabilitySection.Stop();
                }
#endif //DEBUG
            }
            catch (System.OutOfMemoryException e) {
                Connection.Abort(e);
                throw;
            }
            catch (System.StackOverflowException e) {
                Connection.Abort(e);
                throw;
            }
            catch (System.Threading.ThreadAbortException e) {
                Connection.Abort(e);
                SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
                throw;
            }
            finally {
                SqlStatistics.StopTimer(statistics);
            }
        }
        override public void Rollback()
        {
            if (IsYukonPartialZombie)
            {
                // Put something in the trace in case a customer has an issue
                if (Bid.AdvancedOn)
                {
                    Bid.Trace("<sc.SqlTransaction.Rollback|ADV> %d# partial zombie no rollback required\n", ObjectID);
                }
                _internalTransaction = null; // yukon zombification
            }
            else
            {
                ZombieCheck();

                SqlStatistics statistics = null;
                IntPtr        hscp;
                Bid.ScopeEnter(out hscp, "<sc.SqlTransaction.Rollback|API> %d#", ObjectID);
                Bid.CorrelationTrace("<sc.SqlTransaction.Rollback|API|Correlation> ObjectID%d#, ActivityID %ls\n", ObjectID);

                TdsParser bestEffortCleanupTarget = null;
                RuntimeHelpers.PrepareConstrainedRegions();
                try {
#if DEBUG
                    TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();

                    RuntimeHelpers.PrepareConstrainedRegions();
                    try {
                        tdsReliabilitySection.Start();
#else
                    {
#endif //DEBUG
                        bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(_connection);
                        statistics = SqlStatistics.StartTimer(Statistics);

                        _isFromAPI = true;

                        _internalTransaction.Rollback();
                    }
#if DEBUG
                    finally {
                        tdsReliabilitySection.Stop();
                    }
#endif //DEBUG
                }
                catch (System.OutOfMemoryException e) {
                    _connection.Abort(e);
                    throw;
                }
                catch (System.StackOverflowException e) {
                    _connection.Abort(e);
                    throw;
                }
                catch (System.Threading.ThreadAbortException e)  {
                    _connection.Abort(e);
                    SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
                    throw;
                }
                finally {
                    _isFromAPI = false;

                    SqlStatistics.StopTimer(statistics);
                    Bid.ScopeLeave(ref hscp);
                }
            }
        }
Beispiel #14
0
 public override void Open()
 {
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<sc.SqlConnection.Open|API> %d#", this.ObjectID);
     try
     {
         if (this.StatisticsEnabled)
         {
             if (this._statistics == null)
             {
                 this._statistics = new SqlStatistics();
             }
             else
             {
                 this._statistics.ContinueOnNewConnection();
             }
         }
         SNIHandle target = null;
         SqlStatistics statistics = null;
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             statistics = SqlStatistics.StartTimer(this.Statistics);
             this.InnerConnection.OpenConnection(this, this.ConnectionFactory);
             target = SqlInternalConnection.GetBestEffortCleanupTarget(this);
             SqlInternalConnectionSmi innerConnection = this.InnerConnection as SqlInternalConnectionSmi;
             if (innerConnection != null)
             {
                 innerConnection.AutomaticEnlistment();
             }
             else
             {
                 if (this.StatisticsEnabled)
                 {
                     ADP.TimerCurrent(out this._statistics._openTimestamp);
                     this.Parser.Statistics = this._statistics;
                 }
                 else
                 {
                     this.Parser.Statistics = null;
                     this._statistics = null;
                 }
                 this.CompleteOpen();
             }
         }
         catch (OutOfMemoryException exception3)
         {
             this.Abort(exception3);
             throw;
         }
         catch (StackOverflowException exception2)
         {
             this.Abort(exception2);
             throw;
         }
         catch (ThreadAbortException exception)
         {
             this.Abort(exception);
             SqlInternalConnection.BestEffortCleanup(target);
             throw;
         }
         finally
         {
             SqlStatistics.StopTimer(statistics);
         }
     }
     finally
     {
         Bid.ScopeLeave(ref ptr);
     }
 }
        private void WriteRowSourceToServer(int columnCount)
        {
            this.CreateOrValidateConnection("WriteToServer");
            bool flag = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            SNIHandle target = null;

            try
            {
                target = SqlInternalConnection.GetBestEffortCleanupTarget(this._connection);
                this._columnMappings.ReadOnly = true;
                this._localColumnMappings     = this._columnMappings;
                if (this._localColumnMappings.Count > 0)
                {
                    this._localColumnMappings.ValidateCollection();
                    foreach (SqlBulkCopyColumnMapping mapping2 in this._localColumnMappings)
                    {
                        if (mapping2._internalSourceColumnOrdinal == -1)
                        {
                            flag = true;
                            break;
                        }
                    }
                }
                else
                {
                    this._localColumnMappings = new SqlBulkCopyColumnMappingCollection();
                    this._localColumnMappings.CreateDefaultMapping(columnCount);
                }
                if (flag)
                {
                    int ordinal = -1;
                    flag = false;
                    if (this._localColumnMappings.Count > 0)
                    {
                        foreach (SqlBulkCopyColumnMapping mapping in this._localColumnMappings)
                        {
                            if (mapping._internalSourceColumnOrdinal != -1)
                            {
                                continue;
                            }
                            string name = this.UnquotedName(mapping.SourceColumn);
                            switch (this._rowSourceType)
                            {
                            case ValueSourceType.IDataReader:
                                try
                                {
                                    ordinal = ((IDataRecord)this._rowSource).GetOrdinal(name);
                                }
                                catch (IndexOutOfRangeException exception4)
                                {
                                    throw SQL.BulkLoadNonMatchingColumnName(name, exception4);
                                }
                                break;

                            case ValueSourceType.DataTable:
                                ordinal = ((DataTable)this._rowSource).Columns.IndexOf(name);
                                break;

                            case ValueSourceType.RowArray:
                                ordinal = ((DataRow[])this._rowSource)[0].Table.Columns.IndexOf(name);
                                break;
                            }
                            if (ordinal == -1)
                            {
                                throw SQL.BulkLoadNonMatchingColumnName(name);
                            }
                            mapping._internalSourceColumnOrdinal = ordinal;
                        }
                    }
                }
                this.WriteToServerInternal();
            }
            catch (OutOfMemoryException exception3)
            {
                this._connection.Abort(exception3);
                throw;
            }
            catch (StackOverflowException exception2)
            {
                this._connection.Abort(exception2);
                throw;
            }
            catch (ThreadAbortException exception)
            {
                this._connection.Abort(exception);
                SqlInternalConnection.BestEffortCleanup(target);
                throw;
            }
            finally
            {
                this._columnMappings.ReadOnly = false;
            }
        }