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); }
public override void EnlistTransaction(Transaction transaction) { if (transaction != null) { if (this.driver.CurrentTransaction != null) { if (this.driver.CurrentTransaction.BaseTransaction != transaction) { throw new MySqlException("Already enlisted"); } } else { Driver driverInTransaction = DriverTransactionManager.GetDriverInTransaction(transaction); if (driverInTransaction != null) { if (driverInTransaction.IsInActiveUse) { throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported); } string connectionString = driverInTransaction.Settings.GetConnectionString(true); string strB = this.Settings.GetConnectionString(true); if (string.Compare(connectionString, strB, true) != 0) { throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported); } this.CloseFully(); this.driver = driverInTransaction; } if (this.driver.CurrentTransaction == null) { MySqlPromotableTransaction promotableSinglePhaseNotification = new MySqlPromotableTransaction(this, transaction); if (!transaction.EnlistPromotableSinglePhase(promotableSinglePhaseNotification)) { throw new NotSupportedException(Resources.DistributedTxnNotSupported); } this.driver.CurrentTransaction = promotableSinglePhaseNotification; DriverTransactionManager.SetDriverInTransaction(this.driver); this.driver.IsInActiveUse = true; } } } }