Exemplo n.º 1
0
        public MySqlPool(MySqlConnectionStringBuilder settings)
        {
            minSize = settings.MinimumPoolSize;
            maxSize = settings.MaximumPoolSize;

            available = (int)maxSize;
            autoEvent = new AutoResetEvent(false);

            if (minSize > maxSize)
                minSize = maxSize;
            this.settings = settings;
            inUsePool = new List<Driver>((int)maxSize);
            idlePool = new Queue<Driver>((int)maxSize);

            // prepopulate the idle pool to minSize
            for (int i = 0; i < minSize; i++)
                EnqueueIdle(CreateNewPooledConnection());

            procedureCache = new ProcedureCache((int)settings.ProcedureCacheSize);
        }
Exemplo n.º 2
0
        public MySqlPool(MySqlConnectionStringBuilder settings)
        {
            minSize = settings.MinimumPoolSize;
            maxSize = settings.MaximumPoolSize;

            available = (int)maxSize;
            autoEvent = new AutoResetEvent(false);

            if (minSize > maxSize)
            {
                minSize = maxSize;
            }
            this.settings = settings;
            inUsePool     = new List <Driver>((int)maxSize);
            idlePool      = new Queue <Driver>((int)maxSize);

            // prepopulate the idle pool to minSize
            for (int i = 0; i < minSize; i++)
            {
                EnqueueIdle(CreateNewPooledConnection());
            }

            procedureCache = new ProcedureCache((int)settings.ProcedureCacheSize);
        }
Exemplo n.º 3
0
        /// <include file='docs/MySqlConnection.xml' path='docs/Open/*'/>
        public override void Open()
        {
            if (State == ConnectionState.Open)
                throw new InvalidOperationException(Resources.ConnectionAlreadyOpen);

            SetState(ConnectionState.Connecting, true);

#if !CF
            // if we are auto enlisting in a current transaction, then we will be
            // treating the connection as pooled
            if (settings.AutoEnlist && Transaction.Current != null)
            {
                driver = DriverTransactionManager.GetDriverInTransaction(Transaction.Current);
                if (driver != null &&
                    (driver.IsInActiveUse ||
                    !driver.Settings.EquivalentTo(this.Settings)))
                    throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported);
            }
#endif

            try
            {
                if (settings.Pooling)
                {
                    MySqlPool pool = MySqlPoolManager.GetPool(settings);
                    if (driver == null || !driver.IsOpen)
                        driver = pool.GetConnection();
                    procedureCache = pool.ProcedureCache;
                }
                else
                {
                    if (driver == null || !driver.IsOpen)
                        driver = Driver.Create(settings);
                    procedureCache = new ProcedureCache((int)settings.ProcedureCacheSize);
                }
            }
            catch (Exception)
            {
                SetState(ConnectionState.Closed, true);
                throw;
            }

            SetState(ConnectionState.Open, false);
            driver.Configure(this);
            if (settings.Database != null && settings.Database != String.Empty)
                ChangeDatabase(settings.Database);

            // setup our schema provider
            schemaProvider = new ISSchemaProvider(this);
#if !CF
            perfMonitor = new PerformanceMonitor(this);
#endif

            // if we are opening up inside a current transaction, then autoenlist
            // TODO: control this with a connection string option
#if !MONO && !CF
            if (Transaction.Current != null && settings.AutoEnlist)
                EnlistTransaction(Transaction.Current);
#endif

            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }
        /// <include file='docs/MySqlConnection.xml' path='docs/Open/*'/>
        public override void Open()
        {
            if (State == ConnectionState.Open)
            {
                throw new InvalidOperationException(Resources.ConnectionAlreadyOpen);
            }

            SetState(ConnectionState.Connecting, true);

#if !CF
            // if we are auto enlisting in a current transaction, then we will be
            // treating the connection as pooled
            if (settings.AutoEnlist && Transaction.Current != null)
            {
                driver = DriverTransactionManager.GetDriverInTransaction(Transaction.Current);
                if (driver != null &&
                    (driver.IsInActiveUse ||
                     !driver.Settings.EquivalentTo(this.Settings)))
                {
                    throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported);
                }
            }
#endif

            try
            {
                if (settings.Pooling)
                {
                    MySqlPool pool = MySqlPoolManager.GetPool(settings);
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = pool.GetConnection();
                    }
                    procedureCache = pool.ProcedureCache;
                }
                else
                {
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = Driver.Create(settings);
                    }
                    procedureCache = new ProcedureCache((int)settings.ProcedureCacheSize);
                }
            }
            catch (Exception)
            {
                SetState(ConnectionState.Closed, true);
                throw;
            }

            SetState(ConnectionState.Open, false);
            driver.Configure(this);
            if (settings.Database != null && settings.Database != String.Empty)
            {
                ChangeDatabase(settings.Database);
            }

            // setup our schema provider
            schemaProvider = new ISSchemaProvider(this);
#if !CF
            perfMonitor = new PerformanceMonitor(this);
#endif

            // if we are opening up inside a current transaction, then autoenlist
            // TODO: control this with a connection string option
#if !MONO && !CF
            if (Transaction.Current != null && settings.AutoEnlist)
            {
                EnlistTransaction(Transaction.Current);
            }
#endif

            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }