Index: C:/MindTouch/redist/MySql Connector 5.14-MT/Source/MySqlPool.cs
===================================================================
--- C:/MindTouch/redist/MySql Connector 5.14-MT/Source/MySqlPool.cs (revision 7265)
+++ C:/MindTouch/redist/MySql Connector 5.14-MT/Source/MySqlPool.cs (revision 7279)
@@ -193,7 +193,7 @@
}
}
- public Driver GetConnection()
+ public Driver GetConnection(bool allowPooled)
{
// wait till we are allowed in
@@ -206,19 +206,24 @@
// if we get here, then it means that we either have an idle connection
// or room to make a new connection
- try
- {
- Driver d = GetPooledConnection();
- return d;
- }
- catch (Exception ex)
- {
- if (settings.Logging)
- Logger.LogException(ex);
- if (Interlocked.Increment(ref counter) <= 0)
+ try {
+ Driver d = null;
+ if (allowPooled) {
+ d = GetPooledConnection();
+ } else {
+ d = Driver.Create(settings);
+ lock (lockObject) {
+ inUsePool.Add(d);
+ }
+ }
+ return d;
+ } catch (Exception ex) {
+ if (settings.Logging)
+ Logger.LogException(ex);
+ if (Interlocked.Increment(ref counter) <= 0)
poolGate.Release();
- throw;
- }
+ throw;
+ }
}
}
}
Index: C:/MindTouch/redist/MySql Connector 5.14-MT/Source/Connection.cs
===================================================================
--- C:/MindTouch/redist/MySql Connector 5.14-MT/Source/Connection.cs (revision 7265)
+++ C:/MindTouch/redist/MySql Connector 5.14-MT/Source/Connection.cs (revision 7279)
@@ -68,7 +68,7 @@
///
public MySqlConnection()
- : this(null) {
+ : this(string.Empty) {
}
///
@@ -78,11 +78,18 @@
advisor = new UsageAdvisor(this);
database = String.Empty;
- if (connectionString != null) {
+ if (!string.IsNullOrEmpty(connectionString)) {
ConnectionString = connectionString;
}
}
+ internal MySqlConnection(MySqlConnectionStringBuilder settingsObject) {
+ advisor = new UsageAdvisor(this);
+ database = String.Empty;
+
+ settings = settingsObject;
+ }
+
#region Interal Methods & Properties
#if !CF
@@ -431,7 +438,11 @@
}
///
- public override void Open()
+ public override void Open() {
+ Open(true);
+ }
+
+ internal void Open(bool allowPooled)
{
if (State == ConnectionState.Open)
throw new InvalidOperationException(Resources.ConnectionAlreadyOpen);
@@ -455,7 +466,7 @@
{
MySqlPool pool = MySqlPoolManager.GetPool(settings);
if (driver == null)
- driver = pool.GetConnection();
+ driver = pool.GetConnection(allowPooled);
procedureCache = pool.ProcedureCache;
}
else
@@ -549,15 +560,12 @@
internal void Abort()
{
- try
- {
- if (settings.Pooling)
+ try {
+ if (settings.Pooling) {
MySqlPoolManager.RemoveConnection(driver);
- else
- driver.Close();
}
- catch (Exception)
- {
+ driver.Close();
+ } catch (Exception) {
}
SetState(ConnectionState.Closed, true);
}
Index: C:/MindTouch/redist/MySql Connector 5.14-MT/Source/command.cs
===================================================================
--- C:/MindTouch/redist/MySql Connector 5.14-MT/Source/command.cs (revision 7265)
+++ C:/MindTouch/redist/MySql Connector 5.14-MT/Source/command.cs (revision 7279)
@@ -339,8 +339,39 @@
}
}
- ///
- public new MySqlDataReader ExecuteReader(CommandBehavior behavior)
+ ///
+ public new MySqlDataReader ExecuteReader(CommandBehavior behavior) {
+
+ try {
+ return ExecuteReaderInternal(behavior);
+ } catch (MySqlException ex) {
+
+ if (!ex.IsFatal || !connection.Settings.Pooling)
+ throw;
+
+ //At this point the previously failed connection has already been cleaned up and removed from the pool
+ MySqlConnection newConnection = new MySqlConnection(this.connection.Settings);
+
+ //Create a new connection (not from the pool)
+ newConnection.Open(false);
+
+ //Copy the fresh driver to the old MySqlConnection object so that way it can be closed properly (and repooled)
+ this.connection.driver = newConnection.driver;
+
+ //Copy the connection state to the existing MySqlConnection object
+ this.connection.SetState(newConnection.State, false);
+
+ //Change this MySqlCommands's reference to the connection to the new connection
+ this.connection = newConnection;
+
+ //Retry the command.
+ return ExecuteReaderInternal(behavior);
+
+ //Any exception happening here bubbles out to the client
+ }
+ }
+
+ private MySqlDataReader ExecuteReaderInternal(CommandBehavior behavior)
{
lastInsertedId = -1;
CheckState();