问题描述:

I am connecting to MySQL database in C#. I am using 100 percent correct user name and password but I get invalid username/password or error no 1045. I have tried deleting the database and users and recreated all these and assigned all permissions in cpanel but failed. It works on my computer localhost(virtual server). Tried so many times. please help. My code is

 string myConnectionString = @"server=mydomain.co.uk;userid=MyUserID;

password=PasswordOfUser;database=databasename";

MySqlConnection conn = null;

try

{

//MySqlConnection

conn = new MySqlConnection(myConnectionString);

conn.Open();

MessageBox.Show("OK");

conn.Close();

}

catch (MySqlException ex)

{

switch (ex.Number)

{

case 0:

MessageBox.Show("Cannot connect to server. Contact administrator");

break;

case 1042:

MessageBox.Show("Can't get hostname address. Check your internet connection. If does not solve, contact Administrator");

break;

case 1045:

MessageBox.Show("Invalid username/password");

break;

}

}

网友答案:

Error 1045 isn't necessarily just for invalid user/passwd combos. It can indicate that the username you are using to log in does not have the required permissions to access this database.

Try (as root):

GRANT ALL ON database.* TO [email protected] IDENTIFIED by 'password';

or

GRANT ALL ON database.* TO [email protected] IDENTIFIED by 'password';

If you'd like to restrict this user's actions, modify ALL to the specific actions the user is allowed to perform, e.g. SELECT, INSERT, DELETE, etc. (use a comma-separated list for multiple actions).

网友答案:

Enable remote access in cpanel by adding host(IP OR DOMIAN etc)

相关阅读:
Top