jeudi 25 mai 2017

C# to Website Database Connection

Good day!

So here's the situation. 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];
      }

Again, 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. Thanks in advanced!




Aucun commentaire:

Enregistrer un commentaire