Exemplo n.º 1
0
 public override void Open()
 {
     if (this.State == ConnectionState.Open)
     {
         throw new InvalidOperationException(Resources.ConnectionAlreadyOpen);
     }
     this.SetState(ConnectionState.Connecting, true);
     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)))
         {
             throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported);
         }
     }
     try {
         if (this.settings.Pooling)
         {
             MySqlPool pool = MySqlPoolManager.GetPool(this.settings);
             if (this.driver == null)
             {
                 this.driver = pool.GetConnection();
             }
             this.procedureCache = pool.ProcedureCache;
         }
         else
         {
             if (this.driver == null)
             {
                 this.driver = Driver.Create(this.settings);
             }
             this.procedureCache = new GodLesZ.Library.MySql.Data.MySqlClient.ProcedureCache((int)this.settings.ProcedureCacheSize);
         }
     } catch (Exception) {
         this.SetState(ConnectionState.Closed, true);
         throw;
     }
     this.SetState(ConnectionState.Open, false);
     this.driver.Configure(this);
     if ((this.settings.Database != null) && (this.settings.Database != string.Empty))
     {
         this.ChangeDatabase(this.settings.Database);
     }
     if (this.driver.Version.isAtLeast(5, 0, 0))
     {
         this.schemaProvider = new ISSchemaProvider(this);
     }
     else
     {
         this.schemaProvider = new SchemaProvider(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);
 }
Exemplo n.º 2
0
 protected virtual void Dispose(bool disposing)
 {
     if (this.connectionString.Pooling)
     {
         MySqlPoolManager.RemoveConnection(this);
     }
     this.isOpen = false;
 }
Exemplo n.º 3
0
 internal void Abort()
 {
     try {
         if (this.settings.Pooling)
         {
             MySqlPoolManager.ReleaseConnection(this.driver);
         }
         else
         {
             this.driver.Close();
         }
     } catch (Exception) {
     }
     this.SetState(ConnectionState.Closed, true);
 }
Exemplo n.º 4
0
 public void RemoveConnection(Driver driver)
 {
     lock (((ICollection)this.inUsePool).SyncRoot) {
         if (this.inUsePool.Contains(driver))
         {
             this.inUsePool.Remove(driver);
             Interlocked.Increment(ref this.available);
             this.autoEvent.Set();
         }
     }
     if (this.beingCleared && (this.NumConnections == 0))
     {
         MySqlPoolManager.RemoveClearedPool(this);
     }
 }
Exemplo n.º 5
0
 internal void CloseFully()
 {
     if (this.settings.Pooling && this.driver.IsOpen)
     {
         if ((this.driver.ServerStatus & ServerStatusFlags.InTransaction) != 0)
         {
             new MySqlTransaction(this, System.Data.IsolationLevel.Unspecified).Rollback();
         }
         MySqlPoolManager.ReleaseConnection(this.driver);
     }
     else
     {
         this.driver.Close();
     }
     this.driver = null;
 }
Exemplo n.º 6
0
 public static void ClearPool(MySqlConnection connection)
 {
     MySqlPoolManager.ClearPool(connection.Settings);
 }
Exemplo n.º 7
0
 public static void ClearAllPools()
 {
     MySqlPoolManager.ClearAllPools();
 }