'Cannot connect to database when not running on localhost

I created a simple program in Visual Studio 2012 C# that connects to MySQL Database using localhost as my server. The problem is, when I try to connect my program to my website (with the same database as my localhost), I'm getting this error:

Unable to connect to any of the specified MySQL hosts.

Here is what I've done so far:

private void cmdLoadTable_Click(object sender, EventArgs e)
{
    string strServer = "localhost";
    string strPort = "3306";
    string strDatabase = "myDatabase";
    string strUser = "myUser";
    string strPassword = "myPassword";

    MySqlConnection iConnect;
    iConnect = new MySql.Data.MySqlClient.MySqlConnection("server=" + strServer + "; port=" + strPort + "; database=" + strDatabase + "; user id=" + strUser + "; password=" + strPassword);

    iConnect.Open();

    MySqlCommand iCommand = new MySqlCommand("SELECT * from Table1", iConnect);
    MySqlDataAdapter iAdapter = new MySqlDataAdapter(iCommand);
    DataSet iDataSet = new DataSet();
    iAdapter.Fill(iDataSet, "LIST");

    dataGridView1.ReadOnly = true;
    dataGridView1.DataSource = iDataSet.Tables[0];
}

When using localhost (WampServer) as a server, I can connect it successfully. But when I use my website as server online, it throws the said error.

According to my research, web servers didn't allow remote access to their databases. If so, can you please give me other options to update my online database using my C# application?



Solution 1:[1]

Ussualy, you need to add your IP address to white-list at server.

Solution 2:[2]

check your configurations of firewall or other security settings.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Wesley Kai Tian