MySql.Data.MySqlClient.MySqlPool.GetConnection C# (CSharp) Method

GetConnection() public method

public GetConnection ( ) : Driver
return Driver
		public Driver GetConnection() 
		{
			int fullTimeOut = (int)settings.ConnectionTimeout * 1000;
            int timeOut = fullTimeOut;

            DateTime start = DateTime.Now;

            while (timeOut > 0)
            {
                Driver driver = TryToGetDriver();
                if (driver != null) return driver;

                // We have no tickets right now, lets wait for one.
                if (!autoEvent.WaitOne(timeOut, false)) break;
                timeOut = fullTimeOut - (int)DateTime.Now.Subtract(start).TotalMilliseconds;
            }
            throw new MySqlException(Resources.TimeoutGettingConnection);
		}

Usage Example

Exemplo n.º 1
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;
 }
All Usage Examples Of MySql.Data.MySqlClient.MySqlPool::GetConnection