From 672036937671a69426a12936c69efcb54d029e86 Mon Sep 17 00:00:00 2001
From: John Hurliman
Date: Mon, 5 Oct 2009 16:39:40 -0700
Subject: Added CloseDBConnection() to replace the old CloseReaderCommand().
 This will close the MySQLConnection attached to a MySQLCommand. I'm not sure
 if this accounts for every time a database connection needs to be closed, but
 it matches up 1:1 with the places where the database connection was
 previously being closed

---
 OpenSim/Data/MySQL/MySQLAuthenticationData.cs |  8 ++++++--
 OpenSim/Data/MySQL/MySQLFramework.cs          | 14 +++++++-------
 OpenSim/Data/MySQL/MySQLRegionData.cs         |  2 ++
 OpenSim/Data/MySQL/MySQLUserAccountData.cs    |  8 ++++++--
 4 files changed, 21 insertions(+), 11 deletions(-)

(limited to 'OpenSim/Data/MySQL')

diff --git a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs
index e96a123..a41f9f8 100644
--- a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs
+++ b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs
@@ -82,12 +82,16 @@ namespace OpenSim.Data.MySQL
                             ret.Data[s] = result[s].ToString();
                         }
 
+                        CloseDBConnection(cmd);
                         return ret;
                     }
+                    else
+                    {
+                        CloseDBConnection(cmd);
+                        return null;
+                    }
                 }
             }
-
-            return null;
         }
 
         public bool Store(AuthenticationData data)
diff --git a/OpenSim/Data/MySQL/MySQLFramework.cs b/OpenSim/Data/MySQL/MySQLFramework.cs
index c756c9c..f37e9bc 100644
--- a/OpenSim/Data/MySQL/MySQLFramework.cs
+++ b/OpenSim/Data/MySQL/MySQLFramework.cs
@@ -47,7 +47,6 @@ namespace OpenSim.Data.MySQL
         protected MySqlFramework(string connectionString)
         {
             m_Connection = new MySqlConnection(connectionString);
-
             m_Connection.Open();
         }
 
@@ -82,8 +81,7 @@ namespace OpenSim.Data.MySQL
                             errorSeen = true;
 
                             m_Connection.Close();
-                            MySqlConnection newConnection = (MySqlConnection)
-                                    ((ICloneable)m_Connection).Clone();
+                            MySqlConnection newConnection = (MySqlConnection)((ICloneable)m_Connection).Clone();
                             m_Connection.Dispose();
                             m_Connection = newConnection;
                             m_Connection.Open();
@@ -104,14 +102,16 @@ namespace OpenSim.Data.MySQL
         
         protected IDataReader ExecuteReader(MySqlCommand cmd)
         {
-            MySqlConnection newConnection = (MySqlConnection)
-                    ((ICloneable)m_Connection).Clone();
-            
+            MySqlConnection newConnection = (MySqlConnection)((ICloneable)m_Connection).Clone();
             newConnection.Open();
 
             cmd.Connection = newConnection;
-
             return cmd.ExecuteReader();
         }
+
+        protected void CloseDBConnection(MySqlCommand cmd)
+        {
+            cmd.Connection.Dispose();
+        }
     }
 }
diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs
index 04b24b6..3fe27d5 100644
--- a/OpenSim/Data/MySQL/MySQLRegionData.cs
+++ b/OpenSim/Data/MySQL/MySQLRegionData.cs
@@ -172,6 +172,8 @@ namespace OpenSim.Data.MySQL
 
                     retList.Add(ret);
                 }
+
+                CloseDBConnection(cmd);
             }
 
             return retList;
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
index c713a11..38a6f55 100644
--- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
@@ -97,12 +97,16 @@ namespace OpenSim.Data.MySQL
                             ret.Data[s] = result[s].ToString();
                         }
 
+                        CloseDBConnection(cmd);
                         return ret;
                     }
+                    else
+                    {
+                        CloseDBConnection(cmd);
+                        return null;
+                    }
                 }
             }
-
-            return null;
         }
 
         public bool Store(UserAccountData data)
-- 
cgit v1.1