internal PersistenceDBAccessor(DbResourceAllocator dbResourceAllocator, bool enableRetries) { this.dbResourceAllocator = dbResourceAllocator; this.dbRetry = new DbRetry(enableRetries); DbConnection connection = null; short retryCount = 0; Label_001D: try { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService OpenConnection start: " + DateTime.UtcNow.ToString("G", CultureInfo.InvariantCulture)); connection = this.dbResourceAllocator.OpenNewConnection(); WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService. OpenConnection end: " + DateTime.UtcNow.ToString("G", CultureInfo.InvariantCulture)); if ((connection == null) || (ConnectionState.Open != connection.State)) { throw new InvalidOperationException(ExecutionStringManager.InvalidConnection); } } catch (Exception exception) { WorkflowTrace.Host.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService caught exception from OpenConnection: " + exception.ToString()); if (!this.dbRetry.TryDoRetry(ref retryCount)) { throw; } WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService retrying."); goto Label_001D; } this.connection = connection; this.needToCloseConnection = true; }
/// <summary> /// Instantiate an opened connection enlisted to the Transaction /// if promotable is false, the Transaction wraps a local /// transaction inside and can never be promoted /// </summary> /// <param name="dbResourceAllocator"></param> /// <param name="transaction"></param> /// <param name="wantPromotable"></param> internal SharedConnectionInfo( DbResourceAllocator dbResourceAllocator, Transaction transaction, bool wantPromotable, ManualResetEvent handle) { Debug.Assert((transaction != null), "Null Transaction!"); if (null == handle) throw new ArgumentNullException("handle"); this.handle = handle; if (wantPromotable) { // Enlist a newly opened connection to this regular Transaction this.connection = dbResourceAllocator.OpenNewConnection(); this.connection.EnlistTransaction(transaction); } else { // Make this transaction no longer promotable by attaching our // IPromotableSinglePhaseNotification implementation (LocalTranscaction) // and track the DbConnection and DbTransaction associated with the LocalTranscaction LocalTransaction localTransaction = new LocalTransaction(dbResourceAllocator, handle); transaction.EnlistPromotableSinglePhase(localTransaction); this.connection = localTransaction.Connection; this.localTransaction = localTransaction.Transaction; } }
private DbCommand NewStoredProcCommand(string commandText) { DbCommand command = DbResourceAllocator.NewCommand(commandText, this.connection, this.localTransaction); command.CommandType = CommandType.StoredProcedure; return(command); }
internal PersistenceDBAccessor(DbResourceAllocator dbResourceAllocator, Transaction transaction, WorkflowCommitWorkBatchService transactionService) { this.dbResourceAllocator = dbResourceAllocator; this.localTransaction = DbResourceAllocator.GetLocalTransaction(transactionService, transaction); this.connection = this.dbResourceAllocator.GetEnlistedConnection(transactionService, transaction, out this.needToCloseConnection); this.dbRetry = new DbRetry(false); }
protected internal override void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SharedConnectionWorkflowCommitWorkBatchService: Starting"); this.dbResourceAllocator = new DbResourceAllocator(base.Runtime, this.configParameters, this.unvalidatedConnectionString); if (this.transactionConnectionTable == null) { this.transactionConnectionTable = new Dictionary <Transaction, SharedConnectionInfo>(); } if (!this._ignoreCommonEnableRetries && (base.Runtime != null)) { NameValueConfigurationCollection commonParameters = base.Runtime.CommonParameters; if (commonParameters != null) { foreach (string str in commonParameters.AllKeys) { if (string.Compare("EnableRetries", str, StringComparison.OrdinalIgnoreCase) == 0) { this._enableRetries = bool.Parse(commonParameters[str].Value); break; } } } } base.Start(); }
/// <summary> /// Instantiate an opened connection enlisted to the Transaction /// if promotable is false, the Transaction wraps a local /// transaction inside and can never be promoted /// </summary> /// <param name="dbResourceAllocator"></param> /// <param name="transaction"></param> /// <param name="wantPromotable"></param> internal SharedConnectionInfo( DbResourceAllocator dbResourceAllocator, Transaction transaction, bool wantPromotable, ManualResetEvent handle) { Debug.Assert((transaction != null), "Null Transaction!"); if (null == handle) { throw new ArgumentNullException("handle"); } this.handle = handle; if (wantPromotable) { // Enlist a newly opened connection to this regular Transaction this.connection = dbResourceAllocator.OpenNewConnection(); this.connection.EnlistTransaction(transaction); } else { // Make this transaction no longer promotable by attaching our // IPromotableSinglePhaseNotification implementation (LocalTranscaction) // and track the DbConnection and DbTransaction associated with the LocalTranscaction LocalTransaction localTransaction = new LocalTransaction(dbResourceAllocator, handle); transaction.EnlistPromotableSinglePhase(localTransaction); this.connection = localTransaction.Connection; this.localTransaction = localTransaction.Transaction; } }
override protected internal void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SharedConnectionWorkflowCommitWorkBatchService: Starting"); this.dbResourceAllocator = new DbResourceAllocator(this.Runtime, this.configParameters, this.unvalidatedConnectionString); if (this.transactionConnectionTable == null) { this.transactionConnectionTable = new Dictionary <Transaction, SharedConnectionInfo>(); } // // If we didn't find a local value for enable retries // check in the common section if ((!_ignoreCommonEnableRetries) && (null != base.Runtime)) { NameValueConfigurationCollection commonConfigurationParameters = base.Runtime.CommonParameters; if (commonConfigurationParameters != null) { // Then scan for connection string in the common configuration parameters section foreach (string key in commonConfigurationParameters.AllKeys) { if (string.Compare("EnableRetries", key, StringComparison.OrdinalIgnoreCase) == 0) { _enableRetries = bool.Parse(commonConfigurationParameters[key].Value); break; } } } } base.Start(); }
internal LocalTransaction(DbResourceAllocator dbHelper, ManualResetEvent handle) { if (handle == null) { throw new ArgumentNullException("handle"); } this.connection = dbHelper.OpenNewConnectionNoEnlist(); this.transaction = this.connection.BeginTransaction(); this.handle = handle; }
/// <summary> /// Wraps a local transaction inside /// </summary> /// <param name="dbHelper"></param> internal LocalTransaction(DbResourceAllocator dbHelper, ManualResetEvent handle) { if (null == handle) throw new ArgumentNullException("handle"); // Open a connection that specifically does not auto-enlist ("Enlist=false" in connection string) // to prevent auto-promotion of the transaction this.connection = dbHelper.OpenNewConnectionNoEnlist(); this.transaction = this.connection.BeginTransaction(); this.handle = handle; }
protected override void OnStopped() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SharedConnectionWorkflowCommitWorkBatchService: Stopping"); foreach (KeyValuePair <Transaction, SharedConnectionInfo> kvp in this.transactionConnectionTable) { kvp.Value.Dispose(); WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Removing transaction " + kvp.Key.GetHashCode()); } this.transactionConnectionTable.Clear(); this.dbResourceAllocator = null; base.OnStopped(); }
/// <summary> /// Wraps a local transaction inside /// </summary> /// <param name="dbHelper"></param> internal LocalTransaction(DbResourceAllocator dbHelper, ManualResetEvent handle) { if (null == handle) { throw new ArgumentNullException("handle"); } // Open a connection that specifically does not auto-enlist ("Enlist=false" in connection string) // to prevent auto-promotion of the transaction this.connection = dbHelper.OpenNewConnectionNoEnlist(); this.transaction = this.connection.BeginTransaction(); this.handle = handle; }
/// <summary> /// DB access done under a transaction and uses a connection enlisted to this transaction. /// </summary> /// <param name="dbResourceAllocator">Helper to get database connection/command/store procedure parameters/etc</param> /// <param name="transaction">The transaction to do this work under</param> internal PersistenceDBAccessor( DbResourceAllocator dbResourceAllocator, System.Transactions.Transaction transaction, WorkflowCommitWorkBatchService transactionService) { this.dbResourceAllocator = dbResourceAllocator; this.localTransaction = DbResourceAllocator.GetLocalTransaction( transactionService, transaction); // Get a connection enlisted to this transaction, may or may not need to be freed depending on // if the transaction does connection sharing this.connection = this.dbResourceAllocator.GetEnlistedConnection( transactionService, transaction, out needToCloseConnection); // // No retries for external transactions this.dbRetry = new DbRetry(false); }
internal SharedConnectionInfo(DbResourceAllocator dbResourceAllocator, Transaction transaction, bool wantPromotable, ManualResetEvent handle) { if (handle == null) { throw new ArgumentNullException("handle"); } this.handle = handle; if (wantPromotable) { this.connection = dbResourceAllocator.OpenNewConnection(); this.connection.EnlistTransaction(transaction); } else { LocalTransaction promotableSinglePhaseNotification = new LocalTransaction(dbResourceAllocator, handle); transaction.EnlistPromotableSinglePhase(promotableSinglePhaseNotification); this.connection = promotableSinglePhaseNotification.Connection; this.localTransaction = promotableSinglePhaseNotification.Transaction; } }
protected internal override void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({1}): Starting, LoadInternalSeconds={0}", new object[] { this.loadingInterval.TotalSeconds, this._serviceInstanceId.ToString() }); this._dbResourceAllocator = new DbResourceAllocator(base.Runtime, this.configParameters, this.unvalidatedConnectionString); this._transactionService = base.Runtime.GetService <WorkflowCommitWorkBatchService>(); this._dbResourceAllocator.DetectSharedConnectionConflict(this._transactionService); if (!this._ignoreCommonEnableRetries && (base.Runtime != null)) { NameValueConfigurationCollection commonParameters = base.Runtime.CommonParameters; if (commonParameters != null) { foreach (string str in commonParameters.AllKeys) { if (string.Compare("EnableRetries", str, StringComparison.OrdinalIgnoreCase) == 0) { this._enableRetries = bool.Parse(commonParameters[str].Value); break; } } } } base.Start(); }
protected override void OnStopped() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SharedConnectionWorkflowCommitWorkBatchService: Stopping"); foreach (KeyValuePair<Transaction, SharedConnectionInfo> kvp in this.transactionConnectionTable) { kvp.Value.Dispose(); WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Removing transaction " + kvp.Key.GetHashCode()); } this.transactionConnectionTable.Clear(); this.dbResourceAllocator = null; base.OnStopped(); }
override protected internal void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SharedConnectionWorkflowCommitWorkBatchService: Starting"); this.dbResourceAllocator = new DbResourceAllocator(this.Runtime, this.configParameters, this.unvalidatedConnectionString); if (this.transactionConnectionTable == null) this.transactionConnectionTable = new Dictionary<Transaction, SharedConnectionInfo>(); // // If we didn't find a local value for enable retries // check in the common section if ((!_ignoreCommonEnableRetries) && (null != base.Runtime)) { NameValueConfigurationCollection commonConfigurationParameters = base.Runtime.CommonParameters; if (commonConfigurationParameters != null) { // Then scan for connection string in the common configuration parameters section foreach (string key in commonConfigurationParameters.AllKeys) { if (string.Compare("EnableRetries", key, StringComparison.OrdinalIgnoreCase) == 0) { _enableRetries = bool.Parse(commonConfigurationParameters[key].Value); break; } } } } base.Start(); }
protected internal override void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SharedConnectionWorkflowCommitWorkBatchService: Starting"); this.dbResourceAllocator = new DbResourceAllocator(base.Runtime, this.configParameters, this.unvalidatedConnectionString); if (this.transactionConnectionTable == null) { this.transactionConnectionTable = new Dictionary<Transaction, SharedConnectionInfo>(); } if (!this._ignoreCommonEnableRetries && (base.Runtime != null)) { NameValueConfigurationCollection commonParameters = base.Runtime.CommonParameters; if (commonParameters != null) { foreach (string str in commonParameters.AllKeys) { if (string.Compare("EnableRetries", str, StringComparison.OrdinalIgnoreCase) == 0) { this._enableRetries = bool.Parse(commonParameters[str].Value); break; } } } } base.Start(); }
/// <summary> /// DB access done without a transaction in a newly opened connection /// </summary> /// <param name="dbResourceAllocator">Helper to get database connection/command/store procedure parameters/etc</param> internal PersistenceDBAccessor(DbResourceAllocator dbResourceAllocator, bool enableRetries) { this.dbResourceAllocator = dbResourceAllocator; this.dbRetry = new DbRetry(enableRetries); DbConnection conn = null; short count = 0; while (true) { try { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService OpenConnection start: " + DateTime.UtcNow.ToString("G", System.Globalization.CultureInfo.InvariantCulture)); conn = this.dbResourceAllocator.OpenNewConnection(); WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService. OpenConnection end: " + DateTime.UtcNow.ToString("G", System.Globalization.CultureInfo.InvariantCulture)); if ((null == conn) || (ConnectionState.Open != conn.State)) throw new InvalidOperationException(ExecutionStringManager.InvalidConnection); break; } catch (Exception e) { WorkflowTrace.Host.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService caught exception from OpenConnection: " + e.ToString()); if (dbRetry.TryDoRetry(ref count)) { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService retrying."); continue; } throw; } } connection = conn; needToCloseConnection = true; }
override protected internal void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({1}): Starting, LoadInternalSeconds={0}", loadingInterval.TotalSeconds, _serviceInstanceId.ToString()); _dbResourceAllocator = new DbResourceAllocator(this.Runtime, this.configParameters, this.unvalidatedConnectionString); // Check connection string mismatch if using SharedConnectionWorkflowTransactionService _transactionService = Runtime.GetService<WorkflowCommitWorkBatchService>(); _dbResourceAllocator.DetectSharedConnectionConflict(_transactionService); // // If we didn't find a local value for enable retries // check in the common section if ((!_ignoreCommonEnableRetries) && (null != base.Runtime)) { NameValueConfigurationCollection commonConfigurationParameters = base.Runtime.CommonParameters; if (commonConfigurationParameters != null) { // Then scan for connection string in the common configuration parameters section foreach (string key in commonConfigurationParameters.AllKeys) { if (string.Compare(EnableRetriesToken, key, StringComparison.OrdinalIgnoreCase) == 0) { _enableRetries = bool.Parse(commonConfigurationParameters[key].Value); break; } } } } base.Start(); }
internal DbCommand NewCommand() { DbConnection dbConnection = OpenNewConnection(); return(DbResourceAllocator.NewCommand(dbConnection)); }
protected internal override void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({1}): Starting, LoadInternalSeconds={0}", new object[] { this.loadingInterval.TotalSeconds, this._serviceInstanceId.ToString() }); this._dbResourceAllocator = new DbResourceAllocator(base.Runtime, this.configParameters, this.unvalidatedConnectionString); this._transactionService = base.Runtime.GetService<WorkflowCommitWorkBatchService>(); this._dbResourceAllocator.DetectSharedConnectionConflict(this._transactionService); if (!this._ignoreCommonEnableRetries && (base.Runtime != null)) { NameValueConfigurationCollection commonParameters = base.Runtime.CommonParameters; if (commonParameters != null) { foreach (string str in commonParameters.AllKeys) { if (string.Compare("EnableRetries", str, StringComparison.OrdinalIgnoreCase) == 0) { this._enableRetries = bool.Parse(commonParameters[str].Value); break; } } } } base.Start(); }