使用C#MySQL连接器“无法连接到任何指定的MySQL主机”

时间:2019-05-29 16:18:17

标签: c# mysql database mysql-connector

我正在尝试连接到我的MySQL数据库,我可以通过localhost进行此操作。这工作正常,并且连接成功。但是,当我尝试使用公共IP连接时,它无法登录。能够与公共IP连接至关重要。

到目前为止,我有:

  • bind-address=127.0.0.1 / bind-address=::1更改为 bind-address=0.0.0.0 / bind-address=::
  • 将路由器上的端口3306转发到服务器
  • 改写C#代码
  • 尝试使用其他设备(甚至无法通过局域网连接)
  • 检查Windows防火墙是否允许它通过(Windows防火墙已关闭)
  • 每次更改后重新启动WAMP和Windows

一切都在Windows 10上运行,并且WAMP托管一切。

C#代码:

private void Loginbutton_Click(object sender, EventArgs e)
    {
        String username = user.Text;
        String password = pass.Text;

        String server = serverAddress.Text;
        int port = 3306;
        String database = "poppy";
        String connectionString = String.Format("server={0};port={1};user id={2}; password={3}; database={4}", server, port, username, password, database);
        MySqlConnection connection = new MySqlConnection(connectionString);

        try
        {
            connection.Open();

            MessageBox.Show("successful connection");

            connection.Close();
        }
        catch (MySqlException ex)
        {
            MessageBox.Show(ex.Message + connectionString);
        }
    }

错误:

0 个答案:

没有答案