C#和mysql连接错误

时间:2014-11-22 13:48:28

标签: c# mysql visual-studio ip server

我已尝试在Visual Studio中将mysql与c#连接,但它返回异常:"无法连接到任何指定的mysql主机。"

            Debug.WriteLine("metodA LOad");
        string[] lines = System.IO.File.ReadAllLines(@"../../Resources\konfiguracja.conf");

        /*string mojePolaczenie =
        "SERVER=" + lines[0] + ";" +
        "DATABASE=" + lines[1] + ";" +
        "UID=" + lines[2] + ";" +
        "PASSWORD=" + lines[3] + ";";*/

        string mojePolaczenie = "Server=ip;Port=3306;Database=db;Uid=login;Password=pass;";

        MySqlConnection conn = new MySqlConnection(mojePolaczenie);
        MySqlCommand command = conn.CreateCommand();
        command.CommandText = "SELECT * FROM linie";

        try
        {
            conn.Open();
            MessageBox.Show("Otworzyłem połączenie");
        } catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        MySqlDataReader reader = command.ExecuteReader();

        while(reader.Read())
        {
            MessageBox.Show(reader["nrlinii"].ToString());
        }
    }

为什么它不起作用?

感谢所有答案。

0 个答案:

没有答案