public string TestConnection() { try { OpenConnection(); System.Data.ConnectionState connectionState = connection.State; return(connectionState.ToString()); } catch (Exception) { return(string.Empty); } }
async void initDb() { //Create a new connectionstring MySqlConnectionStringBuilder _sb = new MySqlConnectionStringBuilder(); _sb.Server = sqlServer; _sb.Database = sqlDatabase; _sb.UserID = sqlUserID; _sb.Password = sqlPassword; string _cs = _sb.ToString(); //Open new sql connection sqlConnection = new MySqlConnection(_cs); await sqlConnection.OpenAsync(); //Just checking if the connection is valid sqlState = sqlConnection.State; ConsoleLog.Write(ConsoleState.Warning, $"Database connection -> {sqlState.ToString()}"); //Mandatory to close connection after each call. await sqlConnection.CloseAsync(); }