diff --git a/src/Server/SQLHelper.cs b/src/Server/SQLHelper.cs index 95008d8..9d04d03 100644 --- a/src/Server/SQLHelper.cs +++ b/src/Server/SQLHelper.cs @@ -14,6 +14,7 @@ public class SQLHelper { lock (connection) { + EnsureConnected(); using MySqlCommand command = connection.CreateCommand(); command.CommandText = query; foreach (KeyValuePair parameter in parameters) @@ -28,6 +29,7 @@ public class SQLHelper { lock (connection) { + EnsureConnected(); using MySqlCommand command = connection.CreateCommand(); command.CommandText = query; @@ -43,6 +45,7 @@ public class SQLHelper { lock (connection) { + EnsureConnected(); using MySqlCommand command = connection.CreateCommand(); command.CommandText = query; @@ -55,4 +58,21 @@ public class SQLHelper return Convert.ToInt32(command.ExecuteScalar()); } } + + public bool EnsureConnected() + { + if (connection.State != System.Data.ConnectionState.Open) + { + try + { + connection.Close(); + connection.Open(); + } + catch (Exception) + { + throw; // TODO add logging here + } + } + return true; + } } \ No newline at end of file