C#和mysql连接错误

C#和mysql连接错误,c#,mysql,visual-studio,ip,server,C#,Mysql,Visual Studio,Ip,Server,我曾尝试在visual studio中将mysql与c#连接,但它返回异常:“无法连接到任何指定的mysql主机。” 为什么不起作用 谢谢您的回答。conn.Open()抛出异常。我从MysqlConnection conn声明下面的try/catch中移动了这一行。server=ip这意味着您的MySql数据库服务器位于本地网络的外部服务器上?如果是,您是否具有远程访问它所需的权限?mysql数据库位于ext服务器上。我已经检查了连接,一切正常。 Debug.Write

我曾尝试在visual studio中将mysql与c#连接,但它返回异常:“无法连接到任何指定的mysql主机。”

为什么不起作用


谢谢您的回答。

conn.Open()抛出异常。我从MysqlConnection conn声明下面的try/catch中移动了这一行。server=ip这意味着您的MySql数据库服务器位于本地网络的外部服务器上?如果是,您是否具有远程访问它所需的权限?mysql数据库位于ext服务器上。我已经检查了连接,一切正常。
            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());
        }
    }