public override void Open() { if (state == ConnectionState.Open) { throw new InvalidOperationException("The Connection is already Open (State=Open)"); } if (connectionString == null || connectionString.Trim().Length == 0) { throw new InvalidOperationException("Connection string has not been initialized."); } connection = TdsConnectionPool.GetConnection(dataSource, port, deviceId, priority, timeout); try { connection.Open(); } catch (SocketException se) { throw new DbProxyException(se.Message, se); } disposed = false; // reset this, so using () would call Close (). ChangeState(ConnectionState.Open); }
internal static void PutConnection(ITdsConnection connection) { timer.Start(); LinkedList <ITdsConnection> connectionList; int key = connection.GetHashCode(); contentLock.AcquireWriterLock(-1); connectionList = contents[key]; contentLock.ReleaseWriterLock(); listLock.AcquireWriterLock(-1); connectionList.AddFirst(connection); listLock.ReleaseWriterLock(); }
public static void Clear() { Console.WriteLine("Pool clear start!"); timer.Stop(); contentLock.AcquireWriterLock(-1); foreach (LinkedList <ITdsConnection> list in contents.Values) { while (list.Count != 0) { LinkedListNode <ITdsConnection> node = list.First; ITdsConnection connection = node.Value; list.RemoveFirst(); connection.Close(); } } contentLock.ReleaseWriterLock(); timer.Start(); Console.WriteLine("Pool clear end!"); }
/// <summary> /// 构造函数 /// </summary> /// <param name="connection">底层连接类</param> internal PooledTdsConnection(ITdsConnection connection) { this.connection = connection; isOpen = false; }