virtual internal SqlTransaction BeginSqlTransaction(IsolationLevel iso, string transactionName, bool shouldReconnect) { SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Connection.Statistics); 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); } finally { SqlStatistics.StopTimer(statistics); } }
public void WriteToServer(DataRow[] rows) { SqlConnection.ExecutePermission.Demand(); SqlStatistics statistics = this.Statistics; try { statistics = SqlStatistics.StartTimer(this.Statistics); if (rows == null) { throw new ArgumentNullException("rows"); } if (rows.Length != 0) { DataTable table = rows[0].Table; this._rowState = 0; this._rowSource = rows; this._SqlDataReaderRowSource = null; this._rowSourceType = ValueSourceType.RowArray; this._rowEnumerator = rows.GetEnumerator(); this.WriteRowSourceToServer(table.Columns.Count); } } finally { SqlStatistics.StopTimer(statistics); } }
static internal void StopTimer(SqlStatistics statistics) { if (null != statistics) { statistics.ReleaseAndUpdateExecutionTimer(); } }
internal static void StopTimer(SqlStatistics statistics) { if (statistics != null) { statistics.ReleaseAndUpdateExecutionTimer(); } }
override public void Open() { if (StatisticsEnabled) { if (null == _statistics) { _statistics = new SqlStatistics(); } else { _statistics.ContinueOnNewConnection(); } } SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Statistics); if (!TryOpen(null)) { throw ADP.InternalError(ADP.InternalErrorCode.SynchronousConnectReturnedPending); } } finally { SqlStatistics.StopTimer(statistics); } }
public SqlTransaction BeginTransaction(IsolationLevel iso, string transactionName) { WaitForPendingReconnection(); SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Statistics); SqlTransaction transaction; bool isFirstAttempt = true; do { transaction = GetOpenTdsConnection().BeginSqlTransaction(iso, transactionName, isFirstAttempt); // do not reconnect twice Debug.Assert(isFirstAttempt || !transaction.InternalTransaction.ConnectionHasBeenRestored, "Restored connection on non-first attempt"); isFirstAttempt = false; } while (transaction.InternalTransaction.ConnectionHasBeenRestored); // The GetOpenConnection line above doesn't keep a ref on the outer connection (this), // and it could be collected before the inner connection can hook it to the transaction, resulting in // a transaction with a null connection property. Use GC.KeepAlive to ensure this doesn't happen. GC.KeepAlive(this); return(transaction); } finally { SqlStatistics.StopTimer(statistics); } }
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); } }
override public void Rollback() { if (IsYukonPartialZombie) { // Put something in the trace in case a customer has an issue _internalTransaction = null; // yukon zombification } else { ZombieCheck(); SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Statistics); _isFromAPI = true; _internalTransaction.Rollback(); } finally { _isFromAPI = false; SqlStatistics.StopTimer(statistics); } } }
static internal SqlStatistics StartTimer(SqlStatistics statistics) { if ((null != statistics) && !statistics.RequestExecutionTimer()) { // we're re-entrant -- don't bother. statistics = null; } return statistics; }
internal static SqlStatistics StartTimer(SqlStatistics statistics) { if ((statistics != null) && !statistics.RequestExecutionTimer()) { statistics = null; } return(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); } }
internal static SqlStatistics StartTimer(SqlStatistics statistics) { if ((null != statistics) && !statistics.RequestExecutionTimer()) { // we're re-entrant -- don't bother. statistics = null; } return(statistics); }
public override Task OpenAsync(CancellationToken cancellationToken) { PrepareStatisticsForNewConnection(); SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Statistics); TaskCompletionSource <DbConnectionInternal> completion = new TaskCompletionSource <DbConnectionInternal>(); TaskCompletionSource <object> result = new TaskCompletionSource <object>(); if (cancellationToken.IsCancellationRequested) { result.SetCanceled(); return(result.Task); } bool completed; try { completed = TryOpen(completion); } catch (Exception e) { result.SetException(e); return(result.Task); } if (completed) { result.SetResult(null); } else { CancellationTokenRegistration registration = new CancellationTokenRegistration(); if (cancellationToken.CanBeCanceled) { registration = cancellationToken.Register(() => completion.TrySetCanceled()); } OpenAsyncRetry retry = new OpenAsyncRetry(this, completion, result, registration); _currentCompletion = new Tuple <TaskCompletionSource <DbConnectionInternal>, Task>(completion, result.Task); completion.Task.ContinueWith(retry.Retry, TaskScheduler.Default); return(result.Task); } return(result.Task); } finally { SqlStatistics.StopTimer(statistics); } }
internal void Retry(Task <DbConnectionInternal> retryTask) { _registration.Dispose(); try { SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(_parent.Statistics); if (retryTask.IsFaulted) { Exception e = retryTask.Exception.InnerException; _parent.CloseInnerConnection(); _parent._currentCompletion = null; _result.SetException(retryTask.Exception.InnerException); } else if (retryTask.IsCanceled) { _parent.CloseInnerConnection(); _parent._currentCompletion = null; _result.SetCanceled(); } else { bool result; // protect continuation from races with close and cancel lock (_parent.InnerConnection) { result = _parent.TryOpen(_retry); } if (result) { _parent._currentCompletion = null; _result.SetResult(null); } else { _parent.CloseInnerConnection(); _parent._currentCompletion = null; _result.SetException(ADP.ExceptionWithStackTrace(ADP.InternalError(ADP.InternalErrorCode.CompletedConnectReturnedPending))); } } } finally { SqlStatistics.StopTimer(statistics); } } catch (Exception e) { _parent.CloseInnerConnection(); _parent._currentCompletion = null; _result.SetException(e); } }
private bool TryOpen(TaskCompletionSource <DbConnectionInternal> retry) { SqlConnectionString connectionOptions = (SqlConnectionString)ConnectionOptions; // Fail Fast in case an application is trying to enlist the SqlConnection in a Transaction Scope. if (connectionOptions.Enlist && ADP.GetCurrentTransaction() != null) { throw ADP.AmbientTransactionIsNotSupported(); } _applyTransientFaultHandling = (retry == null && connectionOptions != null && connectionOptions.ConnectRetryCount > 0); if (ForceNewConnection) { if (!InnerConnection.TryReplaceConnection(this, ConnectionFactory, retry, UserConnectionOptions)) { return(false); } } else { if (!InnerConnection.TryOpenConnection(this, ConnectionFactory, retry, UserConnectionOptions)) { return(false); } } // does not require GC.KeepAlive(this) because of OnStateChange var tdsInnerConnection = (SqlInternalConnectionTds)InnerConnection; Debug.Assert(tdsInnerConnection.Parser != null, "Where's the parser?"); if (!tdsInnerConnection.ConnectionOptions.Pooling) { // For non-pooled connections, we need to make sure that the finalizer does actually run to avoid leaking SNI handles GC.ReRegisterForFinalize(this); } // The _statistics can change with StatisticsEnabled. Copying to a local variable before checking for a null value. SqlStatistics statistics = _statistics; if (StatisticsEnabled || (s_diagnosticListener.IsEnabled(SqlClientDiagnosticListenerExtensions.SqlAfterExecuteCommand) && statistics != null)) { ADP.TimerCurrent(out _statistics._openTimestamp); tdsInnerConnection.Parser.Statistics = _statistics; } else { tdsInnerConnection.Parser.Statistics = null; _statistics = null; // in case of previous Open/Close/reset_CollectStats sequence } return(true); }
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(); } } }
private void PrepareStatisticsForNewConnection() { if (StatisticsEnabled) { if (null == _statistics) { _statistics = new SqlStatistics(); } else { _statistics.ContinueOnNewConnection(); } } }
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); } } }
private void PrepareStatisticsForNewConnection() { if (StatisticsEnabled || s_diagnosticListener.IsEnabled(SqlClientDiagnosticListenerExtensions.SqlAfterExecuteCommand)) { if (null == _statistics) { _statistics = new SqlStatistics(); } else { _statistics.ContinueOnNewConnection(); } } }
override public void ChangeDatabase(string database) { SqlStatistics statistics = null; RepairInnerConnection(); try { statistics = SqlStatistics.StartTimer(Statistics); InnerConnection.ChangeDatabase(database); } finally { SqlStatistics.StopTimer(statistics); } }
internal virtual SqlTransaction BeginSqlTransaction(System.Data.IsolationLevel iso, string transactionName) { SNIHandle target = null; SqlStatistics statistics = null; SqlTransaction transaction2; RuntimeHelpers.PrepareConstrainedRegions(); try { target = GetBestEffortCleanupTarget(this.Connection); statistics = SqlStatistics.StartTimer(this.Connection.Statistics); SqlConnection.ExecutePermission.Demand(); this.ValidateConnectionForExecute(null); if (this.HasLocalTransactionFromAPI) { throw ADP.ParallelTransactionsNotSupported(this.Connection); } if (iso == System.Data.IsolationLevel.Unspecified) { iso = System.Data.IsolationLevel.ReadCommitted; } SqlTransaction transaction = new SqlTransaction(this, this.Connection, iso, this.AvailableInternalTransaction); this.ExecuteTransaction(TransactionRequest.Begin, transactionName, iso, transaction.InternalTransaction, false); return(transaction); } catch (OutOfMemoryException exception3) { this.Connection.Abort(exception3); throw; } catch (StackOverflowException exception2) { this.Connection.Abort(exception2); throw; } catch (ThreadAbortException exception) { this.Connection.Abort(exception); BestEffortCleanup(target); throw; } finally { SqlStatistics.StopTimer(statistics); } return(transaction2); }
public void Save(string savePointName) { ZombieCheck(); SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Statistics); _internalTransaction.Save(savePointName); } finally { SqlStatistics.StopTimer(statistics); } }
private bool TryOpen(TaskCompletionSource <DbConnectionInternal> retry) { SqlConnectionString connectionOptions = (SqlConnectionString)ConnectionOptions; _applyTransientFaultHandling = (retry == null && connectionOptions != null && connectionOptions.ConnectRetryCount > 0); if (ForceNewConnection) { if (!InnerConnection.TryReplaceConnection(this, ConnectionFactory, retry, UserConnectionOptions)) { return(false); } } else { if (!InnerConnection.TryOpenConnection(this, ConnectionFactory, retry, UserConnectionOptions)) { return(false); } } // does not require GC.KeepAlive(this) because of OnStateChange var tdsInnerConnection = (SqlInternalConnectionTds)InnerConnection; Debug.Assert(tdsInnerConnection.Parser != null, "Where's the parser?"); if (!tdsInnerConnection.ConnectionOptions.Pooling) { // For non-pooled connections, we need to make sure that the finalizer does actually run to avoid leaking SNI handles GC.ReRegisterForFinalize(this); } if (StatisticsEnabled || s_diagnosticListener.IsEnabled(SqlClientDiagnosticListenerExtensions.SqlAfterExecuteCommand)) { ADP.TimerCurrent(out _statistics._openTimestamp); tdsInnerConnection.Parser.Statistics = _statistics; } else { tdsInnerConnection.Parser.Statistics = null; _statistics = null; // in case of previous Open/Close/reset_CollectStats sequence } return(true); }
public override void Rollback() { Exception e = null; Guid operationId = s_diagnosticListener.WriteTransactionRollbackBefore(_isolationLevel, _connection, null); if (IsYukonPartialZombie) { // Put something in the trace in case a customer has an issue _internalTransaction = null; // yukon zombification } else { ZombieCheck(); SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Statistics); _isFromAPI = true; _internalTransaction.Rollback(); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteTransactionRollbackError(operationId, _isolationLevel, _connection, null, e); } else { s_diagnosticListener.WriteTransactionRollbackAfter(operationId, _isolationLevel, _connection, null); } _isFromAPI = false; SqlStatistics.StopTimer(statistics); } } }
internal SqlDataReader(SqlCommand command, CommandBehavior behavior) { this._command = command; this._commandBehavior = behavior; if (this._command != null) { this._timeoutSeconds = command.CommandTimeout; this._connection = command.Connection; if (this._connection != null) { this._statistics = this._connection.Statistics; this._typeSystem = this._connection.TypeSystem; } } this._dataReady = false; this._metaDataConsumed = false; this._hasRows = false; this._browseModeInfoConsumed = false; }
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); } }
override public void Open() { PrepareStatisticsForNewConnection(); SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Statistics); if (!TryOpen(null)) { throw ADP.InternalError(ADP.InternalErrorCode.SynchronousConnectReturnedPending); } } finally { SqlStatistics.StopTimer(statistics); } }
private bool TryOpen(TaskCompletionSource <DbConnectionInternal> retry) { if (ForceNewConnection) { if (!InnerConnection.TryReplaceConnection(this, ConnectionFactory, retry, UserConnectionOptions)) { return(false); } } else { if (!InnerConnection.TryOpenConnection(this, ConnectionFactory, retry, UserConnectionOptions)) { return(false); } } // does not require GC.KeepAlive(this) because of OnStateChange var tdsInnerConnection = (InnerConnection as SqlInternalConnectionTds); Debug.Assert(tdsInnerConnection.Parser != null, "Where's the parser?"); if (!tdsInnerConnection.ConnectionOptions.Pooling) { // For non-pooled connections, we need to make sure that the finalizer does actually run to avoid leaking SNI handles GC.ReRegisterForFinalize(this); } if (StatisticsEnabled) { ADP.TimerCurrent(out _statistics._openTimestamp); tdsInnerConnection.Parser.Statistics = _statistics; } else { tdsInnerConnection.Parser.Statistics = null; _statistics = null; // in case of previous Open/Close/reset_CollectStats sequence } return(true); }
//////////////////////////////////////////////////////////////////////////////////////// // PUBLIC METHODS //////////////////////////////////////////////////////////////////////////////////////// override public void Commit() { ZombieCheck(); SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Statistics); _isFromAPI = true; _internalTransaction.Commit(); } finally { _isFromAPI = false; SqlStatistics.StopTimer(statistics); } }
public void Rollback(string transactionName) { ZombieCheck(); SqlStatistics statistics = null; try { statistics = SqlStatistics.StartTimer(Statistics); _isFromAPI = true; _internalTransaction.Rollback(transactionName); } finally { _isFromAPI = false; SqlStatistics.StopTimer(statistics); } }
public SqlTransaction BeginTransaction(System.Data.IsolationLevel iso, string transactionName) { SqlStatistics statistics = null; SqlTransaction transaction; IntPtr ptr; string str = ADP.IsEmpty(transactionName) ? "None" : transactionName; Bid.ScopeEnter(out ptr, "<sc.SqlConnection.BeginTransaction|API> %d#, iso=%d{ds.IsolationLevel}, transactionName='%ls'\n", this.ObjectID, (int) iso, str); try { statistics = SqlStatistics.StartTimer(this.Statistics); SqlTransaction transaction2 = this.GetOpenConnection().BeginSqlTransaction(iso, transactionName); GC.KeepAlive(this); transaction = transaction2; } finally { Bid.ScopeLeave(ref ptr); SqlStatistics.StopTimer(statistics); } return transaction; }
override public void Open() { Guid operationId = s_diagnosticListener.WriteConnectionOpenBefore(this); PrepareStatisticsForNewConnection(); SqlStatistics statistics = null; Exception e = null; try { statistics = SqlStatistics.StartTimer(Statistics); TaskCompletionSource <DbConnectionInternal> completionSource = null; if (!TryOpen(isAsync: false, completionSource: ref completionSource)) { throw ADP.InternalError(ADP.InternalErrorCode.SynchronousConnectReturnedPending); } } catch (Exception ex) { e = ex; throw; } finally { SqlStatistics.StopTimer(statistics); if (e != null) { s_diagnosticListener.WriteConnectionOpenError(operationId, this, e); } else { s_diagnosticListener.WriteConnectionOpenAfter(operationId, this); } } }
internal static SqlStatistics StartTimer(SqlStatistics statistics) { if ((statistics != null) && !statistics.RequestExecutionTimer()) { statistics = null; } return statistics; }
private void CloseInternal(bool closeReader) { TdsParser parser = this._parser; TdsParserStateObject stateObj = this._stateObj; bool flag2 = this.IsCommandBehavior(CommandBehavior.CloseConnection); this._parser = null; bool flag = false; RuntimeHelpers.PrepareConstrainedRegions(); try { if (((parser != null) && (stateObj != null)) && (stateObj._pendingData && (parser.State == TdsParserState.OpenLoggedIn))) { if (this._altRowStatus == ALTROWSTATUS.AltRow) { this._dataReady = true; } if (this._dataReady) { this.CleanPartialRead(); } parser.Run(RunBehavior.Clean, this._command, this, null, stateObj); } this.RestoreServerSettings(parser, stateObj); } catch (OutOfMemoryException exception6) { this._isClosed = true; flag = true; if (this._connection != null) { this._connection.Abort(exception6); } throw; } catch (StackOverflowException exception5) { this._isClosed = true; flag = true; if (this._connection != null) { this._connection.Abort(exception5); } throw; } catch (ThreadAbortException exception4) { this._isClosed = true; flag = true; if (this._connection != null) { this._connection.Abort(exception4); } throw; } finally { if (flag) { this._isClosed = true; this._command = null; this._connection = null; this._statistics = null; } else if (closeReader) { this._stateObj = null; this._data = null; if (this.Connection != null) { this.Connection.RemoveWeakReference(this); } RuntimeHelpers.PrepareConstrainedRegions(); try { if ((this._command != null) && (stateObj != null)) { stateObj.CloseSession(); } } catch (OutOfMemoryException exception3) { this._isClosed = true; flag = true; if (this._connection != null) { this._connection.Abort(exception3); } throw; } catch (StackOverflowException exception2) { this._isClosed = true; flag = true; if (this._connection != null) { this._connection.Abort(exception2); } throw; } catch (ThreadAbortException exception) { this._isClosed = true; flag = true; if (this._connection != null) { this._connection.Abort(exception); } throw; } this.SetMetaData(null, false); this._dataReady = false; this._isClosed = true; this._fieldNameLookup = null; if (flag2 && (this.Connection != null)) { this.Connection.Close(); } if (this._command != null) { this._recordsAffected = this._command.InternalRecordsAffected; } this._command = null; this._connection = null; this._statistics = null; } } }
internal void Deactivate(bool connectionIsDoomed) { // Called when the connection that owns us is deactivated. if (MARSOn) { _sessionPool.Deactivate(); } Debug.Assert(connectionIsDoomed || null == _pendingTransaction, "pending transaction at disconnect?"); if (!connectionIsDoomed && null != _physicalStateObj) { if (_physicalStateObj._pendingData) { DrainData(_physicalStateObj); } if (_physicalStateObj.HasOpenResult) { // Need to decrement openResultCount for all pending operations. _physicalStateObj.DecrementOpenResultCount(); } } // Any active, non-distributed transaction must be rolled back. We // need to wait for distributed transactions to be completed by the // transaction manager -- we don't want to automatically roll them // back. // // Note that when there is a transaction delegated to this connection, // we will defer the deactivation of this connection until the // transaction manager completes the transaction. SqlInternalTransaction currentTransaction = CurrentTransaction; if (null != currentTransaction && currentTransaction.HasParentTransaction) { currentTransaction.CloseFromConnection(); Debug.Assert(null == CurrentTransaction, "rollback didn't clear current transaction?"); } Statistics = null; // must come after CleanWire or we won't count the stuff that happens there... }
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); } }