public void CloseConnection() { try { // Check if the connection is closed. if (GetMySqlConnection.State == ConnectionState.Closed) { // If connection is open, then close it. if (GetMySqlConnection.State == ConnectionState.Open) { GetMySqlConnection.Close(); } } // Return if closed. else { return; } } catch (MySqlException) { throw; } catch (Exception) { throw; } }
public void OpenConnection() { try { // Check if the connection string is valid. if (GetMySqlConnection.ConnectionString == null) { return; } // Check if connection is already open. if (GetMySqlConnection.State == ConnectionState.Open) { return; } // If validated, open connection. GetMySqlConnection.Open(); Debug.WriteLine($"########## Should open connection: [{GetMySqlConnection.State}] <{GetMySqlConnection.Ping()}> ##########"); } catch (InvalidOperationException) { throw; } catch (MySqlException) { throw; } catch (Exception) { throw; } }
public bool PingServer() { return(GetMySqlConnection.Ping()); }