/// <summary> /// Connects to SQL and prepares a query used to retrieve customer data. /// </summary> internal void Initialize() { _log.Debug("Connecting to DB..."); _connection = new IPSConnection(); int retryCount = 0; while (_connection.State != ConnectionState.Open) { try { _connection.Open(); } catch (Exception ex) { _log.WarnFormat("Failed to connect to DB - {0}", ex.Message); if (++retryCount >= 2) { throw ex; } _log.WarnFormat("Retry attempt {0}", retryCount); Random rand = new Random(); System.Threading.Thread.Sleep(rand.Next(500)); } } _initialized = true; }
protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this._disposed) { if (_connection != null) { if (_connection.State == ConnectionState.Open) { _log.Debug("Disconnecting from DB..."); _connection.Close(); } _connection.Dispose(); _connection = null; } _disposed = true; } }