Пример #1
0
 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;
     }
 }
Пример #2
0
        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;
            }
        }
Пример #3
0
 public bool PingServer()
 {
     return(GetMySqlConnection.Ping());
 }