无法通过C#程序连接到MySQL服务器

时间:2015-05-06 03:57:37

标签: c# mysql

我只是想让我的游戏启动器连接到数据库以获取其登录的详细信息,但它仍然失败。我正在使用Visual Studio 2013,我从mysql站点下载了MySQL驱动程序连接器,我们将非常感谢您的帮助。

CODE:

try
{
    string myConnection = "Server=my_host;Database=user;Uid=my_user;Pwd=my_pass;";
    MySqlConnection myConn = new MySqlConnection(myConnection);

    MySqlCommand SelectCommand = new MySqlCommand("SELECT * FROM login WHERE user='" + this.userName.Text + "' AND pass='" + this.passWord.Text + "';", myConn);

    MySqlDataReader myReader;
    myConn.Open();
    myReader = SelectCommand.ExecuteReader();
    int count = 0;
    while (myReader.Read())
        count = count + 1;

    if (count == 1)
        MessageBox.Show("Username and password is correct");
    else if (count > 1)
        MessageBox.Show("Duplicate username and password. Access is denied.");
    else
        MessageBox.Show("Username and password is incorrect. Please try again.");

    myConn.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

基本上如果还有其他方法让它运转起来请提交答案,我会采取任何措施并尝试一切!

!加布

0 个答案:

没有答案