Error connecting to remote database

2

Good evening, I'm having trouble with the following context:

MySql

Using the line of code below I tried connecting to a remote mysql server to try to access some tables and comes with the following error:

SinceI'vetriedeverythingandsofarIhavenothadanyresultswiththecodebelow:

publicboolIsLogged;publicstringusername;publicstringUAC_L;publicintid;MySqlConnectionmyconnection;MySqlConnectionStringBuilderconn;conn=newMySqlConnectionStringBuilder();conn.Server="mysql2.000webhost.com";
conn.UserID = "a1478344_app";
conn.Password = "SENHA!";
conn.Port = 3306;

myconnection = new MySqlConnection(conn.ToString());
myconnection.Open(); // O Erro ocorre aqui!

#region !OBFUSCATED!
MySqlCommand command_login = myconnection.CreateCommand();
command_login.CommandText = "SELECT usr_id,usr_rname,usr_UASC FROM 'a1478344_app'.'app_users' WHERE usr_email='@email' AND usr_password='@senha'"
command_login.Parameters.AddWithValue("@email", email_t.Text);
command_login.Parameters.AddWithValue("@senha", Base64.Base64Encode(senha_t.Text));

MySqlDataReader reader = command_login.ExecuteReader();
if (reader.Read())
{
id = reader.GetInt32("usr_id");
username = reader.GetString("usr_rname");
UAC_L = reader.GetString("usr_UASC");

MessageBox.Show(string.Format("O Usuário {0} tem o ID {1} com privilégios de {2}", username, id, UAC_L));
myconnection.Close();
}
#endregion

The error happens when after I enter the data of ConnectionString and I apply the method myconnection.Open();

And the code for this error is one of 1042 according to MySqlException.Number. Solution Explorer with the references used.

    
asked by anonymous 19.08.2015 / 01:03

1 answer

2

See if your mysql database has permission to remote connect users.

This command will guarantee this access from any IP ( @'%' ) to user a1478344_app for any database ( *.* ).

GRANT ALL PRIVILEGES
ON *.*
TO 'a1478344_app'@'%'
IDENTIFIED BY 'SENHA!';
    
19.08.2015 / 01:37