Index: MySqlConnectionStringBuilder.cs =================================================================== --- MySqlConnectionStringBuilder.cs (revision 1527) +++ MySqlConnectionStringBuilder.cs (working copy) @@ -56,6 +56,7 @@ bool clearing; bool interactiveSession; bool functionsReturnString; + bool pingOnCheckout; static MySqlConnectionStringBuilder() { @@ -98,6 +99,7 @@ defaultValues.Add(Keyword.AllowUserVariables, false); defaultValues.Add(Keyword.InteractiveSession, false); defaultValues.Add(Keyword.FunctionsReturnString, false); + defaultValues.Add(Keyword.PingOnCheckout, true); } /// @@ -814,6 +816,29 @@ /// #if !CF && !MONO [Category("Pooling")] + [DisplayName("Ping On Checkout")] + [Description("When true, indicates a ping is send to the server when " + + "removed from the pool.")] + [DefaultValue(true)] + [RefreshProperties(RefreshProperties.All)] +#endif + public bool PingOnCheckout + { + get { return pingOnCheckout; } + set + { + SetValue("Ping On Checkout", value); + pingOnCheckout = value; + } + } + + + /// + /// Gets or sets a boolean value indicating if the connection should be reset when retrieved + /// from the pool. + /// +#if !CF && !MONO + [Category("Pooling")] [DisplayName("Connection Reset")] [Description("When true, indicates the connection state is reset when " + "removed from the pool.")] @@ -1156,6 +1181,8 @@ return Keyword.InteractiveSession; case "FUNCTIONS RETURN STRING": return Keyword.FunctionsReturnString; + case "PING ON CHECKOUT": + return Keyword.PingOnCheckout; } throw new ArgumentException(Resources.KeywordNotSupported, key); } @@ -1242,6 +1269,8 @@ return interactiveSession; case Keyword.FunctionsReturnString: return functionsReturnString; + case Keyword.PingOnCheckout: + return pingOnCheckout; default: return null; /* this will never happen */ } @@ -1351,6 +1380,8 @@ interactiveSession = ConvertToBool(value); break; case Keyword.FunctionsReturnString: functionsReturnString = ConvertToBool(value); break; + case Keyword.PingOnCheckout: + pingOnCheckout = ConvertToBool(value); break; } } @@ -1532,6 +1563,7 @@ TreatTinyAsBoolean, AllowUserVariables, InteractiveSession, - FunctionsReturnString + FunctionsReturnString, + PingOnCheckout } } Index: MySqlPool.cs =================================================================== --- MySqlPool.cs (revision 1527) +++ MySqlPool.cs (working copy) @@ -120,20 +120,26 @@ private Driver CheckoutConnection() { Driver driver = (Driver)idlePool.Dequeue(); - - // first check to see that the server is still alive - if (!driver.Ping()) + return driver; + } + + private void CheckConnection(Driver driver) + { + if (settings.PingOnCheckout) { - driver.Close(); - driver = CreateNewPooledConnection(); + // first check to see that the server is still alive + if (!driver.Ping()) + { + driver.Close(); + driver = CreateNewPooledConnection(); + } } // if the user asks us to ping/reset pooled connections // do so now if (settings.ConnectionReset) driver.Reset(); - - return driver; + } /// @@ -142,17 +148,25 @@ private Driver GetPooledConnection() { Driver driver = null; - + bool hasIdle; // if we don't have an idle connection but we have room for a new // one, then create it here. lock ((idlePool as ICollection).SyncRoot) { if (!HasIdleConnections) + { driver = CreateNewPooledConnection(); + hasIdle = false; + } else + { driver = CheckoutConnection(); + hasIdle = true; + } } - + if (hasIdle) + CheckConnection(driver); + Debug.Assert(driver != null); lock ((inUsePool as ICollection).SyncRoot) {