private static MySqlConnection getConnection() { if (connection == null) { // Create and open a connection to the database. connection = schoolDb.accessDatabase(); } if (connection.State == System.Data.ConnectionState.Closed) { // Try to open the connection. try { connection.Open(); } catch (Exception e) { // If unable to connect, output the exception to the console // and return null. Console.Write(e); } } return(connection); }