我在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