[英]Connecting to MySQL Database C#
我需要幫助連接到Web主機上的MySQL Server。 這是我的“登錄”按鈕的代碼,但無法登錄。
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);
}
}
我不確定我是否使用了錯誤的信息進行連接
當我使用Webhost的專用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)
嘗試通過Server=127.0.0.1
通過Server=127.0.0.1
更改Server=localhost
驗證hosts
文件並設置正確的重定向...否則使用Mysql提示符驗證用戶名和密碼是否存在(如果存在)驗證其是否正確寫入了您的連接字符串
我在連接字符串中缺少端口號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.