0

I'm currently developing a c# Login system, but the mysql part won't work.

already tried sudo ufw allow 3306/tcp, but still the error. Also tried with HeidiSql

"Can't connect to MySQL server on '5.230.22.130' (10061)

and yes, the user is %, not localhost!!

Error message:

"SocketException: Unable to connect because the destination computer refused to connect Server 5.230.22.130"

class DB
{

    private MySqlConnection connection =
        new MySqlConnection("Datasource=5.230.22.130;Port=3306;Database=***;uid=sqlAdmin;pwd=***;");
    public void openConnection()
    {
        if (connection.State == System.Data.ConnectionState.Closed)
        {
            connection.Open();
        }
    }

    public void closeConnection()
    {
        if (connection.State == System.Data.ConnectionState.Open)
        {
            connection.Close();
        }
    }

    public MySqlConnection getConnection()
    {
        return connection;
    }
}
  • https://stackoverflow.com/questions/2333400/what-can-be-the-reasons-of-connection-refused-errors – fluidguid Nov 22 '19 at 20:36
  • What happens when you run a MySQL client program (like MySQL Workbench or HeidiSQL) *on the same machine where you're testing your C# program* ? Can you connect from the client program? Verify connectivity from a client program first, then debug your own program. – O. Jones Nov 22 '19 at 20:40
  • I am developing the programm on windows 10 and the mysql server ist at my ubunto 18 server. –  Nov 22 '19 at 20:41
  • Can you connect with a client application such as Workbench, phpmyadmin, etc? It might have to do with your server not allowing remote connections. – pensum Nov 22 '19 at 20:55

1 Answers1

1

Ubuntu per default has an active firewall and unless you have disabled it or opened the port already, connections will be blocked.

You can try to open the firewall for mysql server via console on the ubuntu machine (requires root)

sudo ufw allow 3306/tcp

also make sure the user account you want to connect with allows "%" connection and not only "localhost"

Steven
  • 26
  • 4