/// <summary>
/// Event fired when the Test button is clicked
/// </summary>
private async void TestBtn_Click(object sender, EventArgs e)
{
// Build Connection String
MySqlConnectionStringBuilder Builder = new MySqlConnectionStringBuilder();
Builder.Server = Hostname.Text;
Builder.Port = (uint)Port.Value;
Builder.UserID = Username.Text;
Builder.Password = Password.Text;
Builder.Database = DBName.Text;
// Attempt to connect, reporting any and all errors
try
{
// Show loading form
LoadingForm.ShowScreen(this, true, "Connecting to MySQL Database...");
SetNativeEnabled(false);
// Dont lock up the program
await Task.Run(() =>
{
using (MySqlConnection Connection = new MySqlConnection(Builder.ConnectionString))
{
Connection.Open();
Connection.Close();
}
});
}
catch (Exception E)
{
MessageBox.Show(E.Message, "Connection Error", MessageBoxButtons.OK,
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1,
(MessageBoxOptions)0x40000 // Force window on top
);
return;
}
finally
{
LoadingForm.CloseForm();
SetNativeEnabled(true);
}
// Show success after loading form has been called to close
MessageBox.Show("Connection Successful!", "Success", MessageBoxButtons.OK,
MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,
(MessageBoxOptions)0x40000 // Force window on top
);
}