internal void ReleaseConnection(VoltConnectionProxy connectionProxy, CancelEventArgs args) { if (!this._usePooling || this._connections.Count >= this._maxConnectionsInPool) { return; } this._connections.Add(connectionProxy); if (args == null) { return; } args.Cancel = true; }
/// <summary>Gets the connection.</summary> public IVoltConnection GetConnection() { IVoltConnection result = (IVoltConnection)null; while (this._connections.Count > 0) { this._connections.TryTake(out result); if (result == null || result.IsHealthy) { break; } } if (result == null) { result = new VoltConnectionProxy(this, this._connectionSettings, false); } return(result); }
/// <summary>Gets the open connection.</summary> /// <param name="connectionString">The connection string.</param> /// <param name="useSingleConnection">if set to <c>true</c> [use single connection].</param> /// <returns></returns> public static IVoltConnection GetOpenConnection( string connectionString, bool useSingleConnection = false) { if (!useSingleConnection) { return(GetPool(new ConnectionSettings(connectionString)).GetConnection().Open()); } if (singleConnectionInstance == null) { lock (syncRoot) { if (singleConnectionInstance == null) { singleConnectionInstance = new VoltConnectionProxy(new ConnectionSettings(connectionString), true); } } } try { singleConnectionInstance.Open(); } catch (Exception) { try { if (singleConnectionInstance != null) { singleConnectionInstance.Open(); } } catch (Exception) { singleConnectionInstance = (VoltConnectionProxy)null; throw; } } return((IVoltConnection)singleConnectionInstance); }