public void RemoveConnection(ConnectionAlias alias) { for (int i = 0; i < ConnectionPool.Count; i++) { if (alias.CompareToConnection(ConnectionPool[i].Connection)) { ConnectionPool.RemoveAt(i); break; } } }
public void AddConnection(ConnectionAlias alias, bool persistent) { OdbcConnection newConnection; for (int i = 0; i < ConnectionPool.Count; i++) { if (alias.CompareToConnection(ConnectionPool[i].Connection)) { // This connection already exists if (ConnectionPool[i].Status == ConnectionHolderStatus.Active) { // This connection is currently in use by another object // So create an identical connection instead } } } newConnection = new OdbcConnection(alias.GetConnectionString()); try { newConnection.Open(); if (!persistent) { newConnection.Close(); } } catch (Exception err) { LoggingHelper.Log("Error in ConnectionHandler.AddConnection", LogSeverity.Error, err, false); throw new Exception("The connection test for the newly added connection failed.", err); } // Connection test succeeded ConnectionHolder newConnHold = new ConnectionHolder(newConnection, null); newConnHold.PersistentConnection = persistent; ConnectionPool.Add(newConnHold); }