Summary description for MySqlPool.
Example #1
0
        public static Driver GetConnection(MySqlConnectionString settings)
        {
            // make sure the manager is initialized
            if (MySqlPoolManager.pools == null)
            {
                MySqlPoolManager.Initialize();
            }

            string text = settings.GetConnectionString(true);

            lock (pools.SyncRoot)
            {
                MySqlPool pool;
                if (!pools.Contains(text))
                {
                    pool = new MySqlPool(settings);
                    pools.Add(text, pool);
                }
                else
                {
                    pool          = (pools[text] as MySqlPool);
                    pool.Settings = settings;
                }

                return(pool.GetConnection());
            }
        }
        public static void ReleaseConnection(Driver driver)
        {
            Debug.Assert(driver != null);

            MySqlPool pool = driver.Pool;

            pool?.ReleaseConnection(driver);
        }
		public static void ReleaseConnection(Driver driver)
		{
			MySqlPool pool = driver.Pool;
			if (pool == null)
			{
				return;
			}
			pool.ReleaseConnection(driver);
		}
Example #4
0
 public static void ReleaseConnection(Driver driver)
 {
     lock (pools.SyncRoot)
     {
         string    key  = driver.Settings.GetConnectionString(true);
         MySqlPool pool = (MySqlPool)pools[key];
         if (pool == null)
         {
             throw new MySqlException("Pooling exception: Unable to find original pool for connection");
         }
         pool.ReleaseConnection(driver);
     }
 }
Example #5
0
 private static void ClearPoolByText(string key)
 {
     lock (MySqlPoolManager.pools)
     {
         if (MySqlPoolManager.pools.ContainsKey(key))
         {
             MySqlPool mySqlPool = MySqlPoolManager.pools[key];
             MySqlPoolManager.clearingPools.Add(mySqlPool);
             mySqlPool.Clear();
             MySqlPoolManager.pools.Remove(key);
         }
     }
 }
Example #6
0
        public static void RemoveConnection(Driver driver)
        {
            Debug.Assert(driver != null);

            MySqlPool pool = driver.Pool;

            if (pool == null)
            {
                return;
            }

            pool.RemoveConnection(driver);
        }
Example #7
0
 public static void RemoveConnection(Driver driver)
 {
     lock (MySqlPoolManager.pools.SyncRoot)
     {
         string    connectionString = driver.Settings.GetConnectionString(true);
         MySqlPool mySqlPool        = (MySqlPool)MySqlPoolManager.pools[connectionString];
         if (mySqlPool == null)
         {
             throw new MySqlException("Pooling exception: Unable to find original pool for connection");
         }
         mySqlPool.RemoveConnection(driver);
     }
 }
		private static void ClearPoolByText(string key)
		{
			Dictionary<string, MySqlPool> obj = MySqlPoolManager.pools;
			lock (obj)
			{
				if (MySqlPoolManager.pools.ContainsKey(key))
				{
					MySqlPool mySqlPool = MySqlPoolManager.pools[key];
					MySqlPoolManager.clearingPools.Add(mySqlPool);
					mySqlPool.Clear();
					MySqlPoolManager.pools.Remove(key);
				}
			}
		}
Example #9
0
        private static void ClearPoolByText(string key)
        {
            lock (pools.SyncRoot)
            {
                // add the pool to our list of pools being cleared
                MySqlPool pool = (pools[key] as MySqlPool);
                clearingPools.Add(pool);

                // now tell the pool to clear itself
                pool.Clear();

                // and then remove the pool from the active pools list
                pools.Remove(key);
            }
        }
Example #10
0
        /// <summary>
        /// Remove drivers that have been idle for too long.
        /// </summary>
        public static void CleanIdleConnections(object obj)
        {
            List <Driver> oldDrivers = new List <Driver>();

            lock (pools.SyncRoot)
            {
                foreach (string key in pools.Keys)
                {
                    MySqlPool pool = (pools[key] as MySqlPool);
                    oldDrivers.AddRange(pool.RemoveOldIdleConnections());
                }
            }
            foreach (Driver driver in oldDrivers)
            {
                driver.Close();
            }
        }
Example #11
0
        public static void CleanIdleConnections(object obj)
        {
            List <Driver> list = new List <Driver>();

            lock (MySqlPoolManager.pools)
            {
                foreach (string current in MySqlPoolManager.pools.Keys)
                {
                    MySqlPool mySqlPool = MySqlPoolManager.pools[current];
                    list.AddRange(mySqlPool.RemoveOldIdleConnections());
                }
            }
            foreach (Driver current2 in list)
            {
                current2.Close();
            }
        }
        public static MySqlPool GetPool(MySqlConnectionStringBuilder settings)
        {
            string text = settings.GetConnectionString(true);

            lock (pools.SyncRoot)
            {
                MySqlPool pool = (pools[text] as MySqlPool);
                if (pool == null)
                {
                    pool = new MySqlPool(settings);
                    pools.Add(text, pool);
                }
                else
                    pool.Settings = settings;

                return pool;
            }
        }
		public static void CleanIdleConnections(object obj)
		{
			List<Driver> list = new List<Driver>();
			Dictionary<string, MySqlPool> obj2 = MySqlPoolManager.pools;
			lock (obj2)
			{
				foreach (string current in MySqlPoolManager.pools.Keys)
				{
					MySqlPool mySqlPool = MySqlPoolManager.pools[current];
					list.AddRange(mySqlPool.RemoveOldIdleConnections());
				}
			}
			using (List<Driver>.Enumerator enumerator2 = list.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					enumerator2.Current.Close();
				}
			}
		}
Example #14
0
        public static MySqlPool GetPool(MySqlConnectionStringBuilder settings)
        {
            string text = settings.GetConnectionString(true);

            lock (pools.SyncRoot)
            {
                MySqlPool pool = (pools[text] as MySqlPool);
                if (pool == null)
                {
                    pool = new MySqlPool(settings);
                    pools.Add(text, pool);
                }
                else
                {
                    pool.Settings = settings;
                }

                return(pool);
            }
        }
Example #15
0
        public static void ReleaseConnection(Driver driver)
        {
            string    key  = driver.Settings.GetConnectionString(true);
            MySqlPool pool = (MySqlPool)pools[key];

            // if we can't find the pool but we did get a thread id then we assume
            // something is bad wrong.  If we didn't get a thread id then we assume that
            // the driver connection info was bogus and that led to the pool failing
            // to create
            if (pool == null)
            {
                if (driver.ThreadID != -1)
                {
                    throw new MySqlException("Pooling exception: Unable to find original pool for connection");
                }
            }
            else
            {
                pool.ReleaseConnection(driver);
            }
        }
Example #16
0
        private static void ClearPoolByText(string key)
        {
            lock (pools.SyncRoot)
            {
                // if pools doesn't have it, then this pool must already have been cleared
                if (!pools.ContainsKey(key))
                {
                    return;
                }

                // add the pool to our list of pools being cleared
                MySqlPool pool = (pools[key] as MySqlPool);
                clearingPools.Add(pool);

                // now tell the pool to clear itself
                pool.Clear();

                // and then remove the pool from the active pools list
                pools.Remove(key);
            }
        }
Example #17
0
        public static MySqlPool GetPool(MySqlConnectionStringBuilder settings)
        {
            string    key = MySqlPoolManager.GetKey(settings);
            MySqlPool result;

            lock (MySqlPoolManager.pools)
            {
                MySqlPool mySqlPool;
                MySqlPoolManager.pools.TryGetValue(key, out mySqlPool);
                if (mySqlPool == null)
                {
                    mySqlPool = new MySqlPool(settings);
                    MySqlPoolManager.pools.Add(key, mySqlPool);
                }
                else
                {
                    mySqlPool.Settings = settings;
                }
                result = mySqlPool;
            }
            return(result);
        }
Example #18
0
        public static MySqlPool GetPool(MySqlConnectionString settings)
        {
            string    connectionString = settings.GetConnectionString(true);
            MySqlPool result;

            lock (MySqlPoolManager.pools.SyncRoot)
            {
                MySqlPool mySqlPool;
                if (!MySqlPoolManager.pools.Contains(connectionString))
                {
                    mySqlPool = new MySqlPool(settings);
                    MySqlPoolManager.pools.Add(connectionString, mySqlPool);
                }
                else
                {
                    mySqlPool          = (MySqlPoolManager.pools[connectionString] as MySqlPool);
                    mySqlPool.Settings = settings;
                }
                result = mySqlPool;
            }
            return(result);
        }
        public static MySqlPool GetPool(MySqlConnectionStringBuilder settings)
        {
            string text = GetKey(settings);

            lock (Pools)
            {
                MySqlPool pool;
                Pools.TryGetValue(text, out pool);

                if (pool == null)
                {
                    pool = new MySqlPool(settings);
                    Pools.Add(text, pool);
                }
                else
                {
                    pool.Settings = settings;
                }

                return(pool);
            }
        }
Example #20
0
 public void Open()
 {
     if (this.state == (ConnectionState)1)
     {
         throw new InvalidOperationException(Resources.ConnectionAlreadyOpen);
     }
     this.SetState((ConnectionState)2);
     try
     {
         if (this.settings.Pooling)
         {
             MySqlPool pool = MySqlPoolManager.GetPool(this.settings);
             this.driver         = pool.GetConnection();
             this.procedureCache = pool.ProcedureCache;
         }
         else
         {
             this.driver         = Driver.Create(this.settings);
             this.procedureCache = new ProcedureCache(this.settings.ProcedureCacheSize);
         }
     }
     catch (Exception)
     {
         this.SetState(0);
         throw;
     }
     if (this.driver.Settings.UseOldSyntax)
     {
         Logger.LogWarning("You are using old syntax that will be removed in future versions");
     }
     this.SetState((ConnectionState)1);
     this.driver.Configure(this);
     if (this.settings.Database != null && this.settings.Database.Length != 0)
     {
         this.ChangeDatabase(this.settings.Database);
     }
     this.hasBeenOpen = true;
 }
Example #21
0
        /// <include file='docs/MySqlConnection.xml' path='docs/Open/*'/>
        public override void Open()
        {
            if (State == ConnectionState.Open)
            {
                Throw(new InvalidOperationException(Resources.ConnectionAlreadyOpen));
            }

            // start up our interceptors
            _exceptionInterceptor = new ExceptionInterceptor(this);
            commandInterceptor    = new CommandInterceptor(this);

            SetState(ConnectionState.Connecting, true);

#if !NETSTANDARD1_3
            AssertPermissions();

            //TODO: SUPPORT FOR 452 AND 46X
            // 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
            {
                MySqlConnectionStringBuilder currentSettings = Settings;

                //TODO: SUPPORT FOR 452 AND 46X
                // Load balancing
#if !NETSTANDARD1_3
                if (ReplicationManager.IsReplicationGroup(Settings.Server))
                {
                    if (driver == null)
                    {
                        ReplicationManager.GetNewConnection(Settings.Server, false, this);
                    }
                    else
                    {
                        currentSettings = driver.Settings;
                    }
                }
#endif

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

            SetState(ConnectionState.Open, false);
            driver.Configure(this);

            if (!(driver.SupportsPasswordExpiration && driver.IsPasswordExpired))
            {
                if (!string.IsNullOrEmpty(Settings.Database))
                {
                    ChangeDatabase(Settings.Database);
                }
            }

            // setup our schema provider
            _schemaProvider = new ISSchemaProvider(this);
            PerfMonitor     = new PerformanceMonitor(this);

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

            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }
Example #22
0
 public static void RemoveClearedPool(MySqlPool pool)
 {
     //Debug.Assert(clearingPools.Contains(pool));
     clearingPools.Remove(pool);
 }
Example #23
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);

            //AssertPermissions();

            try
            {
                MySqlConnectionStringBuilder currentSettings = Settings;


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

            // if the user is using old syntax, let them know
            //if (driver.Settings.UseOldSyntax)
            //MySqlTrace.LogWarning(ServerThread,
            //  "You are using old syntax that will be removed in future versions");

            SetState(ConnectionState.Open, false);

            driver.Configure(this);

            if (!(driver.SupportsPasswordExpiration && driver.IsPasswordExpired))
            {
                if (Settings.Database != null && Settings.Database != String.Empty)
                {
                    ChangeDatabase(Settings.Database);
                }
            }

            // setup our schema provider
            schemaProvider = new ISSchemaProvider(this);



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

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

            // start up our interceptors
            _exceptionInterceptor = new ExceptionInterceptor(this);
            commandInterceptor    = new CommandInterceptor(this);

            SetState(ConnectionState.Connecting, true);

            try
            {
                MySqlConnectionStringBuilder currentSettings = Settings;

                //TODO: SUPPORT FOR 452 AND 46X
                // Load balancing

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

            SetState(ConnectionState.Open, false);
            driver.Configure(this);

            if (!(driver.SupportsPasswordExpiration && driver.IsPasswordExpired))
            {
                if (!string.IsNullOrEmpty(Settings.Database))
                {
                    ChangeDatabase(Settings.Database);
                }
            }

            // setup our schema provider
            _schemaProvider = new ISSchemaProvider(this);
            PerfMonitor     = new PerformanceMonitor(this);

            // if we are opening up inside a current transaction, then autoenlist
            // TODO: control this with a connection string option

            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }
Example #25
0
 public override void Open()
 {
     if (this.State == ConnectionState.Open)
     {
         this.Throw(new InvalidOperationException(Resources.ConnectionAlreadyOpen));
     }
     this.exceptionInterceptor = new ExceptionInterceptor(this);
     this.commandInterceptor   = new CommandInterceptor(this);
     this.SetState(ConnectionState.Connecting, true);
     this.AssertPermissions();
     if (this.Settings.AutoEnlist && Transaction.Current != null)
     {
         this.driver = DriverTransactionManager.GetDriverInTransaction(Transaction.Current);
         if (this.driver != null && (this.driver.IsInActiveUse || !this.driver.Settings.EquivalentTo(this.Settings)))
         {
             this.Throw(new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported));
         }
     }
     try
     {
         MySqlConnectionStringBuilder settings = this.Settings;
         if (ReplicationManager.IsReplicationGroup(this.Settings.Server))
         {
             if (this.driver == null)
             {
                 ReplicationManager.GetNewConnection(this.Settings.Server, false, this);
                 return;
             }
             settings = this.driver.Settings;
         }
         if (this.Settings.Pooling)
         {
             MySqlPool pool = MySqlPoolManager.GetPool(settings);
             if (this.driver == null || !this.driver.IsOpen)
             {
                 this.driver = pool.GetConnection();
             }
             this.procedureCache = pool.ProcedureCache;
         }
         else
         {
             if (this.driver == null || !this.driver.IsOpen)
             {
                 this.driver = Driver.Create(settings);
             }
             this.procedureCache = new ProcedureCache((int)this.Settings.ProcedureCacheSize);
         }
     }
     catch (Exception)
     {
         this.SetState(ConnectionState.Closed, true);
         throw;
     }
     if (this.driver.Settings.UseOldSyntax)
     {
         MySqlTrace.LogWarning(this.ServerThread, "You are using old syntax that will be removed in future versions");
     }
     this.SetState(ConnectionState.Open, false);
     this.driver.Configure(this);
     if ((!this.driver.SupportsPasswordExpiration || !this.driver.IsPasswordExpired) && this.Settings.Database != null && this.Settings.Database != string.Empty)
     {
         this.ChangeDatabase(this.Settings.Database);
     }
     this.schemaProvider = new ISSchemaProvider(this);
     this.perfMonitor    = new PerformanceMonitor(this);
     if (Transaction.Current != null && this.Settings.AutoEnlist)
     {
         this.EnlistTransaction(Transaction.Current);
     }
     this.hasBeenOpen = true;
     this.SetState(ConnectionState.Open, true);
 }
Example #26
0
        /// <include file='docs/MySqlConnection.xml' path='docs/Open/*'/>
        public override void Open()
        {
            if (State == ConnectionState.Open)
            {
                Throw(new InvalidOperationException(Resources.ConnectionAlreadyOpen));
            }

#if !RT
            // start up our interceptors
            exceptionInterceptor = new ExceptionInterceptor(this);
            commandInterceptor   = new CommandInterceptor(this);
#endif

            SetState(ConnectionState.Connecting, true);

            AssertPermissions();

#if !RT
            // 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
            {
                MySqlConnectionStringBuilder currentSettings = Settings;

                // Load balancing
                if (ReplicationManager.IsReplicationGroup(Settings.Server))
                {
                    if (driver == null)
                    {
                        ReplicationManager.GetNewConnection(Settings.Server, false, this);
                    }
                    else
                    {
                        currentSettings = driver.Settings;
                    }
                }

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

            // if the user is using old syntax, let them know
            if (driver.Settings.UseOldSyntax)
            {
                MySqlTrace.LogWarning(ServerThread,
                                      "You are using old syntax that will be removed in future versions");
            }

            SetState(ConnectionState.Open, false);
            driver.Configure(this);

            if (!(driver.SupportsPasswordExpiration && driver.IsPasswordExpired))
            {
                if (Settings.Database != null && Settings.Database != String.Empty)
                {
                    ChangeDatabase(Settings.Database);
                }
            }

            // setup our schema provider
            schemaProvider = new ISSchemaProvider(this);
            perfMonitor    = new PerformanceMonitor(this);

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

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

            // start up our interceptors
            _exceptionInterceptor = new ExceptionInterceptor(this);
            commandInterceptor    = new CommandInterceptor(this);

            SetState(ConnectionState.Connecting, true);

            AssertPermissions();

            //TODO: SUPPORT FOR 452 AND 46X
            // 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));
                }
            }

            MySqlConnectionStringBuilder currentSettings = Settings;

            try
            {
                if (Settings.ConnectionProtocol == MySqlConnectionProtocol.Tcp && Settings.IsSshEnabled())
                {
                    _sshHandler = new Ssh(
                        Settings.SshHostName,
                        Settings.SshUserName,
                        Settings.SshPassword,
                        Settings.SshKeyFile,
                        Settings.SshPassphrase,
                        Settings.SshPort,
                        Settings.Server,
                        Settings.Port,
                        false
                        );
                    _sshHandler.StartClient();
                }

                if (!Settings.Pooling || MySqlPoolManager.Hosts == null)
                {
                    FailoverManager.Reset();

                    if (Settings.DnsSrv)
                    {
                        var dnsSrvRecords = DnsResolver.GetDnsSrvRecords(Settings.Server);
                        FailoverManager.SetHostList(dnsSrvRecords.ConvertAll(r => new FailoverServer(r.Target, r.Port, null)),
                                                    FailoverMethod.Sequential);
                    }
                    else
                    {
                        FailoverManager.ParseHostList(Settings.Server, false);
                    }
                }

                // Load balancing && Failover
                if (ReplicationManager.IsReplicationGroup(Settings.Server))
                {
                    if (driver == null)
                    {
                        ReplicationManager.GetNewConnection(Settings.Server, false, this);
                    }
                    else
                    {
                        currentSettings = driver.Settings;
                    }
                }
                else if (FailoverManager.FailoverGroup != null && !Settings.Pooling)
                {
                    FailoverManager.AttemptConnection(this, Settings.ConnectionString, out string connectionString);
                    currentSettings.ConnectionString = connectionString;
                }

                if (Settings.Pooling)
                {
                    if (FailoverManager.FailoverGroup != null)
                    {
                        FailoverManager.AttemptConnection(this, Settings.ConnectionString, out string connectionString, true);
                        currentSettings.ConnectionString = connectionString;
                    }

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

            SetState(ConnectionState.Open, false);
            driver.Configure(this);

            if (driver.IsPasswordExpired && Settings.Pooling)
            {
                MySqlPoolManager.ClearPool(currentSettings);
            }

            if (!(driver.SupportsPasswordExpiration && driver.IsPasswordExpired))
            {
                if (!string.IsNullOrEmpty(Settings.Database))
                {
                    ChangeDatabase(Settings.Database);
                }
            }

            // setup our schema provider
            _schemaProvider = new ISSchemaProvider(this);
            PerfMonitor     = new PerformanceMonitor(this);

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

            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }
Example #28
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);

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

            // if the user is using old syntax, let them know
            if (driver.Settings.UseOldSyntax)
            {
                Logger.LogWarning("You are using old syntax that will be removed in future versions");
            }

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

            // setup our schema provider
            if (driver.Version.isAtLeast(5, 0, 0))
            {
                schemaProvider = new ISSchemaProvider(this);
            }
            else
            {
                schemaProvider = new SchemaProvider(this);
            }
            perfMonitor = new PerformanceMonitor(this);

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

            hasBeenOpen = true;
        }
 public static void RemoveClearedPool(MySqlPool pool)
 {
     Debug.Assert(clearingPools.Contains(pool));
     clearingPools.Remove(pool);
 }
        public static MySqlPool GetPool(MySqlConnectionStringBuilder settings)
        {
            string text = GetKey(settings);

              lock (pools)
              {
            MySqlPool pool;
            pools.TryGetValue(text, out pool);

            if (pool == null)
            {
              pool = new MySqlPool(settings);
              pools.Add(text, pool);
            }
            else
              pool.Settings = settings;

            return pool;
              }
        }
Example #31
0
 public static void RemoveClearedPool(MySqlPool pool)
 {
     MySqlPoolManager.clearingPools.Remove(pool);
 }
        /// <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;
            }

            // if the user is using old syntax, let them know
            if (driver.Settings.UseOldSyntax)
            {
                MySqlTrace.LogWarning(ServerThread,
                                      "You are using old syntax that will be removed in future versions");
            }

            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);
        }