private static TimeSpan _timeSpan = new TimeSpan(10); // 10 = 0.001 millisecond public static async Task <PooledConnection> GetConnection(string connectionString) { PooledConnection pooledConnection = null; if (_connectionsCreated) { while (!_stack.TryPop(out pooledConnection)) { await Task.Delay(_timeSpan); } return(pooledConnection); } else { pooledConnection = new PooledConnection(); pooledConnection.OdbcConnection = new OdbcConnection(connectionString); _createdConnections++; if (_createdConnections == _maxConnections) { _connectionsCreated = true; } pooledConnection.Number = _createdConnections; pooledConnection.PooledCommands = new ConcurrentDictionary <string, PooledCommand>(); //Console.WriteLine("opened connection number: " + pooledConnection.Number); return(pooledConnection); } }
public static void ReleaseConnection(PooledConnection pooledConnection) { PooledConnection stackedConnection = new PooledConnection(); stackedConnection.OdbcConnection = pooledConnection.OdbcConnection; stackedConnection.Number = pooledConnection.Number; stackedConnection.PooledCommands = pooledConnection.PooledCommands; _stack.Push(stackedConnection); }
public static void Dispose(PooledConnection pooledConnection) { PooledConnection newPooledConnection = new PooledConnection(); newPooledConnection.DbConnection = pooledConnection.DbConnection; newPooledConnection.Number = pooledConnection.Number; newPooledConnection.PooledCommands = pooledConnection.PooledCommands; Release(newPooledConnection); }
public static void Release(PooledConnection pooledConnection) { TaskCompletionSource <PooledConnection> taskCompletionSource; if (_waitingQueue.TryDequeue(out taskCompletionSource)) { taskCompletionSource.SetResult(pooledConnection); } else { pooledConnection.Released = true; _stack.Push(pooledConnection); } }
public static async Task <PooledConnection> GetConnection(string connectionString) { PooledConnection pooledConnection = null; if (_connectionsCreated) { if (_stack.TryPop(out pooledConnection)) { pooledConnection.Released = false; } else { pooledConnection = await GetPooledConnectionAsync(); } return(pooledConnection); } else { pooledConnection = new PooledConnection(); if (DataProvider.IsOdbcConnection) { pooledConnection.DbConnection = new OdbcConnection(connectionString); } else { //For future use with non odbc drivers which can be AOT compiled without reflection //pooledConnection.DbConnection = new NpgsqlConnection(connectionString); } _createdConnections++; if (_createdConnections == _maxConnections) { _connectionsCreated = true; } pooledConnection.Number = _createdConnections; pooledConnection.PooledCommands = new ConcurrentDictionary <string, PooledCommand>(); //Console.WriteLine("opened connection number: " + pooledConnection.Number); return(pooledConnection); } }
public static void ReleaseConnection(PooledConnection pooledConnection) { TaskCompletionSource <PooledConnection> taskCompletionSource; PooledConnection stackedConnection = new PooledConnection(); stackedConnection.OdbcConnection = pooledConnection.OdbcConnection; stackedConnection.Number = pooledConnection.Number; stackedConnection.PooledCommands = pooledConnection.PooledCommands; if (_waitingQueue.TryDequeue(out taskCompletionSource)) { taskCompletionSource.SetResult(stackedConnection); } else { _stack.Push(stackedConnection); } }
public static async Task <PooledConnection> GetConnection(string connectionString) { PooledConnection pooledConnection = null; if (_connectionsCreated) { if (_stack.TryPop(out pooledConnection)) { pooledConnection.Released = false; } else { pooledConnection = await GetPooledConnectionAsync(); } return(pooledConnection); } else { pooledConnection = new PooledConnection(); #if ADO pooledConnection.DbConnection = new Npgsql.NpgsqlConnection(connectionString); #else pooledConnection.DbConnection = new System.Data.Odbc.OdbcConnection(connectionString); #endif _createdConnections++; if (_createdConnections == _maxConnections) { _connectionsCreated = true; } pooledConnection.Number = _createdConnections; pooledConnection.PooledCommands = new ConcurrentDictionary <string, PooledCommand>(); //Console.WriteLine("opened connection number: " + pooledConnection.Number); return(pooledConnection); } }
internal PooledCommand(IDbCommand dbCommand, PooledConnection pooledConnection) { _dbCommand = dbCommand; _pooledConnection = pooledConnection; }
public PooledCommand(string commandText, CommandType commandType, PooledConnection pooledConnection) { pooledConnection.GetCommand(commandText, commandType, this); }
public PooledCommand(PooledConnection pooledConnection) { _dbCommand = pooledConnection.CreateCommand(); _pooledConnection = pooledConnection; }
public static async Task <PooledConnection> GetConnection(string connectionString) { int i = 0; PooledConnection pooledConnection; if (_createdConnections < _maxConnections) { pooledConnection = new PooledConnection(); pooledConnection.OdbcConnection = new OdbcConnection(connectionString); _createdConnections++; pooledConnection.Number = _createdConnections; pooledConnection.PooledCommands = new ConcurrentDictionary <string, PooledCommand>(); //Console.WriteLine("opened connection number: " + pooledConnection.Number); return(pooledConnection); } else { while (!_stack.TryPop(out pooledConnection) && i < _maxLoops) { if (i < 5) { await Task.Delay(1); } else if (i < 10) { await Task.Delay(2); } else if (i < 25) { await Task.Delay(3); } else if (i < 50) { await Task.Delay(4); } else if (i < 100) { await Task.Delay(5); } else if (i < 500) { await Task.Delay(10); } else { await Task.Delay(20); } i++; //Console.WriteLine("waiting: " + i); } if (i < _maxLoops) { //Console.WriteLine("opened connection number: " + pooledConnection.Number); return(pooledConnection); } else { throw new Exception("No connections are available"); } } }
internal PooledCommand(OdbcCommand odbcCommand, PooledConnection pooledConnection) { _odbcCommand = odbcCommand; _pooledConnection = pooledConnection; }
public PooledCommand(PooledConnection pooledConnection) { _odbcCommand = (OdbcCommand)pooledConnection.CreateCommand(); _pooledConnection = pooledConnection; }