diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs index 6ac8cc3dd4..5006aaf244 100644 --- a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs @@ -75,6 +75,7 @@ namespace OpenGrid.Framework.Data.MySQL } catch (Exception e) { + database.Reconnect(); Console.WriteLine(e.ToString()); return null; } @@ -106,6 +107,7 @@ namespace OpenGrid.Framework.Data.MySQL } catch (Exception e) { + database.Reconnect(); Console.WriteLine(e.ToString()); return null; } @@ -137,6 +139,7 @@ namespace OpenGrid.Framework.Data.MySQL } catch (Exception e) { + database.Reconnect(); Console.WriteLine(e.ToString()); return null; } diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs index aee18b9609..2eaa158be8 100644 --- a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs @@ -16,6 +16,7 @@ namespace OpenGrid.Framework.Data.MySQL class MySQLManager { IDbConnection dbcon; + string connectionString; /// /// Initialises and creates a new MySQL connection and maintains it. @@ -29,7 +30,7 @@ namespace OpenGrid.Framework.Data.MySQL { try { - string connectionString = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; + connectionString = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; dbcon = new MySqlConnection(connectionString); dbcon.Open(); @@ -51,6 +52,28 @@ namespace OpenGrid.Framework.Data.MySQL dbcon = null; } + /// + /// Reconnects to the database + /// + public void Reconnect() + { + lock (dbcon) + { + try + { + // Close the DB connection + dbcon.Close(); + // Try reopen it + dbcon = new MySqlConnection(connectionString); + dbcon.Open(); + } + catch (Exception e) + { + Console.WriteLine("Unable to reconnect to database " + e.ToString()); + } + } + } + /// /// Runs a query with protection against SQL Injection by using parameterised input. /// @@ -70,10 +93,47 @@ namespace OpenGrid.Framework.Data.MySQL return (IDbCommand)dbcommand; } - catch (Exception e) + catch { - Console.WriteLine("Failed during Query generation: " + e.ToString()); - return null; + lock (dbcon) + { + // Close the DB connection + try + { + dbcon.Close(); + } + catch { } + + // Try reopen it + try + { + dbcon = new MySqlConnection(connectionString); + dbcon.Open(); + } + catch (Exception e) + { + Console.WriteLine("Unable to reconnect to database " + e.ToString()); + } + + // Run the query again + try + { + MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); + dbcommand.CommandText = sql; + foreach (KeyValuePair param in parameters) + { + dbcommand.Parameters.Add(param.Key, param.Value); + } + + return (IDbCommand)dbcommand; + } + catch (Exception e) + { + // Return null if it fails. + Console.WriteLine("Failed during Query generation: " + e.ToString()); + return null; + } + } } } diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs index 57dbfc6cd2..6f3cad6c15 100644 --- a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs @@ -51,6 +51,7 @@ namespace OpenGrid.Framework.Data.MySQL } catch (Exception e) { + database.Reconnect(); Console.WriteLine(e.ToString()); return null; } @@ -78,6 +79,7 @@ namespace OpenGrid.Framework.Data.MySQL } catch (Exception e) { + database.Reconnect(); Console.WriteLine(e.ToString()); return null; } @@ -116,6 +118,7 @@ namespace OpenGrid.Framework.Data.MySQL } catch (Exception e) { + database.Reconnect(); Console.WriteLine(e.ToString()); return null; } diff --git a/OpenGridServices/OpenGridServices.UserServer/UserManager.cs b/OpenGridServices/OpenGridServices.UserServer/UserManager.cs index cd806217e5..21ecc50eba 100644 --- a/OpenGridServices/OpenGridServices.UserServer/UserManager.cs +++ b/OpenGridServices/OpenGridServices.UserServer/UserManager.cs @@ -395,10 +395,23 @@ namespace OpenGridServices.UserServer // If user specified additional start, use that if (requestData.ContainsKey("start")) { - string startLoc = (string)requestData["start"]; + string startLoc = ((string)requestData["start"]).Trim(); if (!(startLoc == "last" || startLoc == "home")) { - // Ignore it! Heh. + // Format: uri:Ahern&162&213&34 + try + { + string[] parts = startLoc.Remove(0, 4).Split('&'); + string region = parts[0]; + + //////////////////////////////////////////////////// + //SimProfile SimInfo = new SimProfile(); + //SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey); + } + catch (Exception e) + { + + } } }