Welcome aboard! We are happy you are here and wish you good net-raft!
//Initialize
private void Initialize()
{
server = "localhost";
database = "yourdatabase";
uid = "username";
password = "password";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
}
// open connection
private bool OpenConnection()
{
try
{
connection.Open();
return true;
}
catch (MySqlException ex)
{
switch (ex.Number)
{
case 0:
MessageBox.Show("Connection is refused!");
break;
case 1045:
MessageBox.Show("Invalid username/password!");
break;
}
return false;
}
}
The most helpful C# solutions