aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-05-30 02:36:48 +0000
committerAdam Frisby2007-05-30 02:36:48 +0000
commitb0de1b93f9ddc7a111d72ea03eae32ff486089a1 (patch)
tree7286e30966ce16fde5d2f03a2612725fec5c85be /OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
parentAnother rebuild of the build files! :O (diff)
downloadopensim-SC_OLD-b0de1b93f9ddc7a111d72ea03eae32ff486089a1.zip
opensim-SC_OLD-b0de1b93f9ddc7a111d72ea03eae32ff486089a1.tar.gz
opensim-SC_OLD-b0de1b93f9ddc7a111d72ea03eae32ff486089a1.tar.bz2
opensim-SC_OLD-b0de1b93f9ddc7a111d72ea03eae32ff486089a1.tar.xz
* Added reconnect support for MySQL Data interfaces if they time out. (Grid/User modes only now, Log todo)
* Begun writing support for supporting the "Start" region login parameter.
Diffstat (limited to '')
-rw-r--r--OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs68
1 files changed, 64 insertions, 4 deletions
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
index aee18b9..2eaa158 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
16 class MySQLManager 16 class MySQLManager
17 { 17 {
18 IDbConnection dbcon; 18 IDbConnection dbcon;
19 string connectionString;
19 20
20 /// <summary> 21 /// <summary>
21 /// Initialises and creates a new MySQL connection and maintains it. 22 /// Initialises and creates a new MySQL connection and maintains it.
@@ -29,7 +30,7 @@ namespace OpenGrid.Framework.Data.MySQL
29 { 30 {
30 try 31 try
31 { 32 {
32 string connectionString = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; 33 connectionString = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";";
33 dbcon = new MySqlConnection(connectionString); 34 dbcon = new MySqlConnection(connectionString);
34 35
35 dbcon.Open(); 36 dbcon.Open();
@@ -52,6 +53,28 @@ namespace OpenGrid.Framework.Data.MySQL
52 } 53 }
53 54
54 /// <summary> 55 /// <summary>
56 /// Reconnects to the database
57 /// </summary>
58 public void Reconnect()
59 {
60 lock (dbcon)
61 {
62 try
63 {
64 // Close the DB connection
65 dbcon.Close();
66 // Try reopen it
67 dbcon = new MySqlConnection(connectionString);
68 dbcon.Open();
69 }
70 catch (Exception e)
71 {
72 Console.WriteLine("Unable to reconnect to database " + e.ToString());
73 }
74 }
75 }
76
77 /// <summary>
55 /// Runs a query with protection against SQL Injection by using parameterised input. 78 /// Runs a query with protection against SQL Injection by using parameterised input.
56 /// </summary> 79 /// </summary>
57 /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> 80 /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
@@ -70,10 +93,47 @@ namespace OpenGrid.Framework.Data.MySQL
70 93
71 return (IDbCommand)dbcommand; 94 return (IDbCommand)dbcommand;
72 } 95 }
73 catch (Exception e) 96 catch
74 { 97 {
75 Console.WriteLine("Failed during Query generation: " + e.ToString()); 98 lock (dbcon)
76 return null; 99 {
100 // Close the DB connection
101 try
102 {
103 dbcon.Close();
104 }
105 catch { }
106
107 // Try reopen it
108 try
109 {
110 dbcon = new MySqlConnection(connectionString);
111 dbcon.Open();
112 }
113 catch (Exception e)
114 {
115 Console.WriteLine("Unable to reconnect to database " + e.ToString());
116 }
117
118 // Run the query again
119 try
120 {
121 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
122 dbcommand.CommandText = sql;
123 foreach (KeyValuePair<string, string> param in parameters)
124 {
125 dbcommand.Parameters.Add(param.Key, param.Value);
126 }
127
128 return (IDbCommand)dbcommand;
129 }
130 catch (Exception e)
131 {
132 // Return null if it fails.
133 Console.WriteLine("Failed during Query generation: " + e.ToString());
134 return null;
135 }
136 }
77 } 137 }
78 } 138 }
79 139