aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLFramework.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MySQL/MySQLFramework.cs62
1 files changed, 13 insertions, 49 deletions
diff --git a/OpenSim/Data/MySQL/MySQLFramework.cs b/OpenSim/Data/MySQL/MySQLFramework.cs
index fca0ca5..3fdcf1e 100644
--- a/OpenSim/Data/MySQL/MySQLFramework.cs
+++ b/OpenSim/Data/MySQL/MySQLFramework.cs
@@ -40,12 +40,16 @@ namespace OpenSim.Data.MySQL
40 /// </summary> 40 /// </summary>
41 public class MySqlFramework 41 public class MySqlFramework
42 { 42 {
43 protected MySqlConnection m_Connection; 43 private static readonly log4net.ILog m_log =
44 log4net.LogManager.GetLogger(
45 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
46
47 protected string m_connectionString;
48 protected object m_dbLock = new object();
44 49
45 protected MySqlFramework(string connectionString) 50 protected MySqlFramework(string connectionString)
46 { 51 {
47 m_Connection = new MySqlConnection(connectionString); 52 m_connectionString = connectionString;
48 m_Connection.Open();
49 } 53 }
50 54
51 ////////////////////////////////////////////////////////////// 55 //////////////////////////////////////////////////////////////
@@ -55,64 +59,24 @@ namespace OpenSim.Data.MySQL
55 // 59 //
56 protected int ExecuteNonQuery(MySqlCommand cmd) 60 protected int ExecuteNonQuery(MySqlCommand cmd)
57 { 61 {
58 lock (m_Connection) 62 lock (m_dbLock)
59 { 63 {
60 cmd.Connection = m_Connection; 64 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
61
62 bool errorSeen = false;
63
64 while (true)
65 { 65 {
66 dbcon.Open();
67 cmd.Connection = dbcon;
68
66 try 69 try
67 { 70 {
68 return cmd.ExecuteNonQuery(); 71 return cmd.ExecuteNonQuery();
69 } 72 }
70 catch (MySqlException e)
71 {
72 if (errorSeen)
73 throw;
74
75 // This is "Server has gone away" and "Server lost"
76 //
77 if (e.Number == 2006 || e.Number == 2013)
78 {
79 errorSeen = true;
80
81 m_Connection.Close();
82 MySqlConnection newConnection =
83 (MySqlConnection)((ICloneable)m_Connection).Clone();
84 m_Connection.Dispose();
85 m_Connection = newConnection;
86 m_Connection.Open();
87
88 cmd.Connection = m_Connection;
89 }
90 else
91 throw;
92 }
93 catch (Exception e) 73 catch (Exception e)
94 { 74 {
75 m_log.Error(e.Message, e);
95 return 0; 76 return 0;
96 } 77 }
97 } 78 }
98 } 79 }
99 } 80 }
100
101 protected IDataReader ExecuteReader(MySqlCommand cmd)
102 {
103 MySqlConnection newConnection =
104 (MySqlConnection)((ICloneable)m_Connection).Clone();
105 newConnection.Open();
106
107 cmd.Connection = newConnection;
108 return cmd.ExecuteReader();
109 }
110
111 protected void CloseReaderCommand(MySqlCommand cmd)
112 {
113 cmd.Connection.Close();
114 cmd.Connection.Dispose();
115 cmd.Dispose();
116 }
117 } 81 }
118} 82}