public bool IsConnect(bool useTunnel = true) { bool result = true; if (Connection == null) { result = false; try { if (!String.IsNullOrEmpty(DatabaseName) && (!useTunnel || BudeTunnel.Open())) { string port = (useTunnel ? BudeTunnel.TunnelPort : 3307).ToString(); string connstring = string.Format($"Host={serverTunnel}; Port={port}; database={DatabaseName}; User={userName}; password={Password}"); Connection = new MySqlConnection(connstring); Connection.Open(); result = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "StaffordMySQLConnection"); } } return(result); }
public void Close() { Connection.Close(); Connection = null; BudeTunnel.Close(); }