我在C#和MySQL中創建了一個系統,但我一直收到這個令人沮喪的錯誤,「無法連接到任何指定的MySQL主機」。我嘗試了許多不同的東西,但沒有任何工作,有人可以試圖幫助我嗎?C# - 無法連接到任何指定的MySQL主機
public bool tryLogin(string username, string password)
{
MySqlConnection con = new MySqlConnection("host=hostremoved;user=user_removed;password=passwordremoved;database=databaseremoved;");
MySqlCommand cmd = new MySqlCommand("SELECT * FROM login WHERE user_name = '" + username + "' AND user_pass = '" + password + "';");
cmd.Connection = con;
con.Open();
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.Read() != false)
{
if (reader.IsDBNull(0) == true)
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
return false;
}
else
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
return true;
}
}
else
{
return false;
}
}
private void btnlogin_Click(object sender, EventArgs e)
{
if (tryLogin(txtuser.Text, txtpass.Text) == true)
{
MessageBox.Show("Login worked!");
}
else
{
MessageBox.Show("Login failed!");
**不要以純文本格式存儲密碼** – SLaks 2013-04-21 21:32:43
您有一個SQL注入漏洞。 – SLaks 2013-04-21 21:33:12
好的,我會解決這兩件事情,但是你知道如何幫助解決我需要幫助的實際問題嗎? – Marooca 2013-04-21 21:41:44