Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i have a web server on internet i am using php/mysql. for my website, now i want to connect to my mysql database on my webserver using my c# windows form application so that i will be able to view,create, update, delete the data on mysql database on webserver, i want to user same database for website and my desktop application. i want any one having my desktop application would be able to update my database on my webserver(i mean not only form some specific ip). Here is my code when i try to run it shows error "Unable to connect to any of specified MySQL hosts." can any one Guide me how to do it. Thanks. The following code is working fine for localhost but not working for web-server which is on internet.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient; // for mysql

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string con_str = "SERVER=fdb4.biz.nf;Port=3306;DATABASE=1558711_zee;UID=1558711_zee;PASSWORD=multan321;compress=true;";


            MySqlConnection connection = new MySqlConnection(con_str);

            try {
                connection.Open();
                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT * FROM  zeetable";
                MySqlDataAdapter mda = new MySqlDataAdapter(cmd);
                DataSet mds = new DataSet();
                mda.Fill(mds);
                dataGridView1.DataSource = mds.Tables[0].DefaultView;
            }
            catch(MySqlException ex){

                MessageBox.Show(ex.Message);
            }
        }

        }
    }
share|improve this question
2  
You have a SQL server on the internet of which you've just posted the address, username and password too. –  Arran Nov 26 '13 at 15:39
    
Is the port open on that host to connect to the database? It's usually not a good idea to directly open a database to the internet like this. Traditionally you would build a web service to run on that server, exposing specifically the API you need, and your client application(s) would connect to that web service. –  David Nov 26 '13 at 15:40
    
Thanks David how can i know is that 3306 port is open on host or not..? or if this is not a good idea to to directly open a database to the internet like this. then how can i build web service API to accomplish my needs...? –  user3860897 Nov 26 '13 at 15:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.