Error connecting remote database

Asked

Viewed 460 times

2

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

MySql

Using the line of code below I tried to connect to a remote mysql server to try to access some tables and comes the following error: inserir a descrição da imagem aqui

Since I have tried everything and so far I have not achieved any result with the code below:

public bool IsLogged;
        public string username;
        public string UAC_L;
        public int id;

        MySqlConnection myconnection;

MySqlConnectionStringBuilder conn;
conn = new MySqlConnectionStringBuilder();
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 from ConnectionString and apply the method myconnection.Open();

And the code of that error is one such 1042 as per Mysqlexception.Number. Solution Explorer with the references used.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • 1

    Are you sure the database connection information is correct? I ask only to exclude this hypothesis :)

  • Yes they are! I checked and everything! but in the same way it is this error!

  • A doubt the explorer Solution is right?

  • You have checked if you can actually connect manually to the server mysql2.000webhost.com? I mean, even if your credentials are correct, there could be some problem connecting your machine to the server.

  • yes it is the mysql server of 000webhost

1 answer

2


See if your mysql database has permission for remote connection of users.

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

GRANT ALL PRIVILEGES
ON *.*
TO 'a1478344_app'@'%'
IDENTIFIED BY 'SENHA!';
  • I’ll try now...

  • ops! gave error Error SQL query: GRANT ALL PRIVILEGES ON DATABASE . To 'a1478344_app'@'%' IDENTIFIED BY 'newpassword' Mysql said: Documentation #1064 - You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use 'near database. * TO 'a1478344_app'@'%' IDENTIFIED BY newpassword 'at line 2

  • I ran it like mysql_query

  • Fixed. Try it again.

  • #1045 - Access denied for user 'a1478344_app'@'localhost' (using password: YES)

  • and now what could have caused this? Let me ask you if you know a site that hosts mysql for free

  • another error has appeared #1064 - You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near ''%' IDENTIFIED BY 'PASSWORD! ' at line 1

  • 1

    I am suspicious that 000webhost does not accept remote connections without account upgrade: http://www.000webhost.com/faq.php?ID=27.

  • Eita! did not know that only against premium could! and now how I will make the login/registration system in my app...

  • I’m glad you showed me this link!

  • you don’t happen to know a server that hosts mysql with remote access?

  • something else, I have an old pc, but it works, so as I would to be able to configure Windows server 2008 R2 on it to host game servers and websites?

  • Unfortunately I do not know a good site that hosts a free Mysql database. I would try to set up a Mysql database on your own machine, if this is possible for you.

  • :( well already thank you! because if it were not you I would not even know that 000webhost had no remote access!

  • Dherik... Is the Microsoft sql server database very difficult to work with or is it the same as mysql? and the Microsoft sql server database is allowed in php?

  • The basic usage is very similar, you will not have difficulties if you already know Mysql. Yes, you can use Sql Server with PHP normally.

Show 11 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.