public void LifeTimeIsTakenInAccount () { var SMALLEST_LIFETIME_TO_TEST = 1; var WAIT_TO_MAKE_LIFETIME_PASSED = 2; TdsConnectionPoolManager sqlConnectionPools = new FakeConnectionPoolManager (); TdsConnectionInfo info = new TdsConnectionInfo ("dummy", 0, 0, 0, 1 /*minpoolsize*/, 1 /*maxpoolsize*/, SMALLEST_LIFETIME_TO_TEST/*lifetime*/); TdsConnectionPool pool = sqlConnectionPools.GetConnectionPool ("test",info); Mono.Data.Tds.Protocol.Tds tds, tds2 = null; tds = pool.GetConnection(); System.Threading.Thread.Sleep (TimeSpan.FromSeconds (WAIT_TO_MAKE_LIFETIME_PASSED)); pool.ReleaseConnection (tds); tds2 = pool.GetConnection (); Assert.IsFalse (object.ReferenceEquals (tds, tds2)); pool.ReleaseConnection(tds2); }
public TdsConnectionPool(TdsConnectionPoolManager manager, TdsConnectionInfo info) { this.info = info; this.manager = manager; conns = new ArrayList(info.PoolMaxSize); available = new Queue(info.PoolMaxSize); InitializePool(); }
public TdsConnectionPool GetConnectionPool (string connectionString, TdsConnectionInfo info) { TdsConnectionPool pool = (TdsConnectionPool) pools [connectionString]; if (pool == null) { pools [connectionString] = new TdsConnectionPool (this, info); pool = (TdsConnectionPool) pools [connectionString]; } return pool; }
public TdsConnectionPool GetConnectionPool(string connectionString, TdsConnectionInfo info) { TdsConnectionPool pool = (TdsConnectionPool)pools [connectionString]; if (pool == null) { pools [connectionString] = new TdsConnectionPool(this, info); pool = (TdsConnectionPool)pools [connectionString]; } return(pool); }
public virtual ITds CreateConnection (TdsConnectionInfo info) { switch (version) { case TdsVersion.tds42: return new Tds42 (info.DataSource, info.Port, info.PacketSize, info.Timeout); case TdsVersion.tds50: return new Tds50 (info.DataSource, info.Port, info.PacketSize, info.Timeout); case TdsVersion.tds70: return new Tds70 (info.DataSource, info.Port, info.PacketSize, info.Timeout); case TdsVersion.tds80: return new Tds80 (info.DataSource, info.Port, info.PacketSize, info.Timeout); } throw new NotSupportedException (); }
public virtual Tds CreateConnection (TdsConnectionInfo info) { //Console.WriteLine ("CreateConnection: TdsVersion:{0}", version); switch (version) { case TdsVersion.tds42: return new Tds42 (info.DataSource, info.Port, info.PacketSize, info.Timeout); case TdsVersion.tds50: return new Tds50 (info.DataSource, info.Port, info.PacketSize, info.Timeout); case TdsVersion.tds70: return new Tds70 (info.DataSource, info.Port, info.PacketSize, info.Timeout); case TdsVersion.tds80: return new Tds80 (info.DataSource, info.Port, info.PacketSize, info.Timeout); } throw new NotSupportedException (); }
public virtual Tds CreateConnection(TdsConnectionInfo info) { //Console.WriteLine ("CreateConnection: TdsVersion:{0}", version); switch (version) { case TdsVersion.tds42: return(new Tds42(info.DataSource, info.Port, info.PacketSize, info.Timeout)); case TdsVersion.tds50: return(new Tds50(info.DataSource, info.Port, info.PacketSize, info.Timeout)); case TdsVersion.tds70: return(new Tds70(info.DataSource, info.Port, info.PacketSize, info.Timeout, info.LifeTime)); case TdsVersion.tds80: return(new Tds80(info.DataSource, info.Port, info.PacketSize, info.Timeout, info.LifeTime)); } throw new NotSupportedException(); }
public override Mono.Data.Tds.Protocol.Tds CreateConnection (TdsConnectionInfo info) { return new FakeTds (info.LifeTime); }
public void CheckNullException() { //set up dummy sql listener, if there is a real sql server on this //machine at that port, in theory this part will fail, but that's ok //becuase something will be listening on the port and that's all we //require at this point: a listener on port 1433... try{ Socket Listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress hostIP =Dns.GetHostEntry("localhost").AddressList[0]; IPEndPoint ep = new IPEndPoint(hostIP, 1433); Listener.Bind(ep); Listener.Listen(1); } catch (Exception){ //ignore } //try to connect twice, in earlier failure would get null exception //on 2nd call to pool.GetConnection(); //Most of this code ripped from sqlConnection.Open() TdsConnectionPool pool; TdsConnectionPoolManager sqlConnectionPools = new TdsConnectionPoolManager(TdsVersion.tds80); TdsConnectionInfo info= new TdsConnectionInfo(SERVER/*dummyhost*/,1433/*port*/, 8192/*pktsize*/,15/*timeout*/,0/*minpoolsize*/, 100/*maxpoolsize*/); pool=sqlConnectionPools.GetConnectionPool("test",info); Tds tds=null; //this first one succeeded regardless as long as something answered //the phone on port 1433 of localhost tds=pool.GetConnection(); pool.ReleaseConnection(tds); // 2nd time thru: This will fail with nullreferenceexception // at pool.GetConnection() unless the patch by Rob Wilkens which // adds "result=null;" before retry in pool.getConnection() source //First let's pretend we're calling this test fresh, as if we //call sqlConnection.Open() again : info=new TdsConnectionInfo(SERVER/*dummyhost*/,1433/*port*/, 8192/*pktsize*/,15/*timeout*/,0/*minpoolsize*/, 100/*maxpoolsize*/); pool=sqlConnectionPools.GetConnectionPool("test",info); //Then: Test for failure (will raise uncaught exception which //causes failure of test if bug is not fixed tds=pool.GetConnection(); pool.ReleaseConnection(tds); //exit }
void Open () { string serverName = string.Empty; 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."); try { if (!pooling) { if(!ParseDataSource (dataSource, out port, out serverName)) throw new SqlException(20, 0, "SQL Server does not exist or access denied.", 17, "ConnectionOpen (Connect()).", dataSource, parms.ApplicationName, 0); tds = new Tds80 (serverName, port, PacketSize, ConnectionTimeout, 0); tds.Pooling = false; } else { if(!ParseDataSource (dataSource, out port, out serverName)) throw new SqlException(20, 0, "SQL Server does not exist or access denied.", 17, "ConnectionOpen (Connect()).", dataSource, parms.ApplicationName, 0); TdsConnectionInfo info = new TdsConnectionInfo (serverName, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize, connectionLifeTime); pool = sqlConnectionPools.GetConnectionPool (connectionString, info); tds = pool.GetConnection (); } } catch (TdsTimeoutException e) { throw SqlException.FromTdsInternalException ((TdsInternalException) e); } catch (TdsInternalException e) { throw SqlException.FromTdsInternalException (e); } tds.TdsErrorMessage += new TdsInternalErrorMessageEventHandler (ErrorHandler); tds.TdsInfoMessage += new TdsInternalInfoMessageEventHandler (MessageHandler); if (!tds.IsConnected) { try { if (Credentials != null) { if (parms.User != String.Empty) throw new ArgumentException("UserID already specified"); if (parms.PasswordSet) throw new ArgumentException("Password already specified"); if (parms.DomainLogin != false) throw new ArgumentException("Cannot use credentials with DomainLogin"); parms.User = Credentials.UserId; parms.Password = Credentials.Password; } tds.Connect (parms); } catch { if (pooling) pool.ReleaseConnection (tds); throw; } } disposed = false; // reset this, so using () would call Close (). ChangeState (ConnectionState.Open); }
public TdsConnectionPool (TdsConnectionPoolManager manager, TdsConnectionInfo info) { this.info = info; this.manager = manager; conns = new ArrayList (info.PoolMaxSize); available = new Queue (info.PoolMaxSize); InitializePool (); }
public void Open () { string serverName = ""; if (connectionString == null || connectionString.Equals ("")) throw new InvalidOperationException ("Connection string has not been initialized."); try { if (!pooling) { ParseDataSource (dataSource, out port, out serverName); tds = new Tds50 (serverName, port, PacketSize, ConnectionTimeout); } else { ParseDataSource (dataSource, out port, out serverName); TdsConnectionInfo info = new TdsConnectionInfo (serverName, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize); pool = sybaseConnectionPools.GetConnectionPool (connectionString, info); tds = pool.GetConnection (); } } catch (TdsTimeoutException e) { throw SybaseException.FromTdsInternalException ((TdsInternalException) e); } tds.TdsErrorMessage += new TdsInternalErrorMessageEventHandler (ErrorHandler); tds.TdsInfoMessage += new TdsInternalInfoMessageEventHandler (MessageHandler); if (!tds.IsConnected) { try { tds.Connect (parms); ChangeState (ConnectionState.Open); ChangeDatabase (parms.Database); } catch { if (pooling) pool.ReleaseConnection (tds); throw; } } else if (connectionReset) { // tds.ExecuteNonQuery ("EXEC sp_reset_connection"); FIXME ChangeState (ConnectionState.Open); } }
public TdsConnectionPool (TdsConnectionPoolManager manager, TdsConnectionInfo info) { this.info = info; this.manager = manager; }
void Open () { string serverName = ""; if (connectionString == null) throw new InvalidOperationException ("Connection string has not been initialized."); try { if (!pooling) { if(!ParseDataSource (dataSource, out port, out serverName)) throw new SqlException(20, 0, "SQL Server does not exist or access denied.", 17, "ConnectionOpen (Connect()).", dataSource, parms.ApplicationName, 0); tds = new Tds70 (serverName, port, PacketSize, ConnectionTimeout); } else { if(!ParseDataSource (dataSource, out port, out serverName)) throw new SqlException(20, 0, "SQL Server does not exist or access denied.", 17, "ConnectionOpen (Connect()).", dataSource, parms.ApplicationName, 0); TdsConnectionInfo info = new TdsConnectionInfo (serverName, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize); pool = sqlConnectionPools.GetConnectionPool (connectionString, info); tds = pool.GetConnection (); } } catch (TdsTimeoutException e) { throw SqlException.FromTdsInternalException ((TdsInternalException) e); } tds.TdsErrorMessage += new TdsInternalErrorMessageEventHandler (ErrorHandler); tds.TdsInfoMessage += new TdsInternalInfoMessageEventHandler (MessageHandler); if (!tds.IsConnected) { try { tds.Connect (parms); } catch { if (pooling) pool.ReleaseConnection (tds); throw; } } /* Not sure ebout removing these 2 lines. * The command that gets to the sql server is just * 'sp_reset_connection' and it fails. * Either remove them definitely or fix it else if (connectionReset) tds.ExecProc ("sp_reset_connection"); */ disposed = false; // reset this, so using () would call Close (). ChangeState (ConnectionState.Open); }