static void Main () { if (Environment.GetEnvironmentVariable ("MONO_TESTS_ODBC") == null) return; OdbcConnection conn = new OdbcConnection (CreateOdbcConnectionString ()); conn.Open (); string dbName = Environment.GetEnvironmentVariable ("MONO_TESTS_SQL_DB"); Assert.AreEqual (dbName, conn.Database, "#1"); OdbcCommand cmd = new OdbcCommand ("CREATE DATABASE aфbиc", conn); cmd.ExecuteNonQuery (); cmd.Dispose (); try { Assert.AreEqual (dbName, conn.Database, "#2"); conn.ChangeDatabase ("aфbиc"); Assert.AreEqual ("aфbиc", conn.Database, "#3"); conn.ChangeDatabase (dbName); Assert.AreEqual (dbName, conn.Database, "#4"); } finally { conn.Dispose (); conn = new OdbcConnection (CreateOdbcConnectionString ()); conn.Open (); cmd = new OdbcCommand ("DROP DATABASE aфbиc", conn); cmd.ExecuteNonQuery (); cmd.Dispose (); } }
private void Thread_Start() { bool connected = false; OdbcConnection connection = null; OdbcCommand command = null; OdbcTransaction transact = null; DateTime start = DateTime.UtcNow; bool shouldWriteException = true; while (true) { m_Sync.WaitOne(); while (m_Queue.Count > 0) { try { object obj = m_Queue.Dequeue(); if (obj == null) { if (connected) { if (transact != null) { try { transact.Commit(); } catch (Exception commitException) { Console.WriteLine("MyRunUO: Exception caught when committing transaction"); Console.WriteLine(commitException); try { transact.Rollback(); Console.WriteLine("MyRunUO: Transaction has been rolled back"); } catch (Exception rollbackException) { Console.WriteLine("MyRunUO: Exception caught when rolling back transaction"); Console.WriteLine(rollbackException); } } } if (connection != null) { try { connection.Close(); } catch { } try { connection.Dispose(); } catch { } } if (command != null) { try { command.Dispose(); } catch { } } try { m_Sync.Close(); } catch { } Console.WriteLine(m_CompletionString, (DateTime.UtcNow - start).TotalSeconds); m_HasCompleted = true; return; } try { connected = true; connection = new OdbcConnection(m_ConnectionString); connection.Open(); connection.ChangeDatabase(Config.Options.ConnectionInfo.Database); command = connection.CreateCommand(); if (Config.Options.UseTransactions) { transact = connection.BeginTransaction(); command.Transaction = transact; } } catch (Exception e) { try { if (transact != null) { transact.Rollback(); } } catch { } try { if (connection != null) { connection.Close(); } } catch { } try { if (connection != null) { connection.Dispose(); } } catch { } try { if (command != null) { command.Dispose(); } } catch { } try { m_Sync.Close(); } catch { } Console.WriteLine("MyRunUO: Unable to connect to the database"); Console.WriteLine(e); m_HasCompleted = true; return; } } else if (obj is string) { if (command != null) { command.CommandText = (string)obj; command.ExecuteNonQuery(); } } else { if (command != null) { var parms = (string[])obj; command.CommandText = parms[0]; if (command.ExecuteScalar() == null) { command.CommandText = parms[1]; command.ExecuteNonQuery(); } } } } catch (Exception e) { if (!shouldWriteException) { continue; } Console.WriteLine("MyRunUO: Exception caught in database thread"); Console.WriteLine(e); shouldWriteException = false; } } lock (m_Queue.SyncRoot) { if (m_Queue.Count == 0) { m_Sync.Reset(); } } } }