0
我需要帮助连接到我的Web主机上的MySQL服务器。下面是我的登录按钮的代码,但它无法登录我进去。连接到MySQL数据库C#
private void btnLogin_Click(object sender, EventArgs e)
{
try
{
string strConnect = "Server=localhost;Database=cpr_users;Uid=MyUsername;password=*******;";
MySqlConnection myConn = new MySqlConnection(strConnect);
MySqlCommand selectCmd = new MySqlCommand("select * from cpr_users.cpr_user_info where username='" + txtUsername.Text + "' and password='" + txtPassword.Text + "' ;", myConn);
MySqlDataReader myReader;
myConn.Open();
int count = 0;
myReader = selectCmd.ExecuteReader();
while (myReader.Read())
{
count = count + 1;
}
if (count == 1)
{
this.Close();
MedicalForm();
}
else if (count > 1)
{
MessageBox.Show("Theres 2 Users with that username Please contact Your_Name_Here ...Access Denied");
}
else
MessageBox.Show("Username or Password is Not correct .. Please try Again!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我不确定我是否使用了错误的信息,用于连接
当我用我的虚拟主机的专用IP和登录我提示以下错误
Authentication to host '**IP ADDRESS**' for user 'MyUsername' using method 'mysql_native_password' failed with message: Access denied for user 'MyUsername'@'myipaddress' (using password: YES)
具体*如何*失败? – David 2014-12-05 18:10:34
“无法连接到任何指定的MySQL主机。” @Steve – 2014-12-05 18:11:37
而你的虚拟主机是你的本地主机? – Steve 2014-12-05 18:12:29