From fbbed6f03d2ba0cd0f4c4c00561718d08ffd270c Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Sat, 21 Jun 2025 14:18:25 +0200 Subject: [PATCH] Attempt to fix MySQL timeout --- src/Server/SQLHelper.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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