Exception says Host 'XX' is not allowed to connect to this MySQL Server. I am using VB.Net, I have a Connect.vb class that connects to MySQL and it has a create database if not exists query.
MySqlConnection conn = new MySqlConnection("server=localhost;uid=root;pwd=root;");
MySqlCommand pst = new MySqlCommand();
try
{
conn.Open();
pst.Connection = conn;
pst.CommandText = "CREATE DATABASE IF NOT EXISTS StocksManagerDB";
pst.ExecuteNonQuery();
conn.Close();
conn = new MySqlConnection("server=localhost;database=StocksManagerDB;uid=root;pwd=root;");
conn.Open();
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Failure to connect to database.\nApplication will now exit.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
conn.Close();
Application.Exit();
}
The create database query executes properly. but when I log in at the login form it gives me that exception. I already tried this but it still gives me same exception. This is the code for the Login. in the load event i put this
conn = Connect.ConnectDB()
and this is the code when fo the button_click event in login
conn.Open();
pst.CommandText = "SELECT * FROM tblLogin WHERE `Username` ='" + txtUsername.Text + "' AND `Password` ='" + txtPassword.Text + "'";
rs = pst.ExecuteReader();
if (rs.Read() == true)
{
Login_Success();
}
else
{
MessageBox.Show("Login Failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUsername.Clear();
txtPassword.Clear();
txtUsername.Focus();
}
conn.Close();