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