简体   繁体   中英

unable to connect any specified mysql hosts

I am creating one windows form application in c# which use MySQL database. whenever I am inserting data through my form to specified "server ip" it throws error like "unable to connect any specified MySQL". when I sending data to localhost,it works. so can you guys please tell me how can I send data to specified "server IP". Help me folks. Thanks in advance.

Here's my code:

{                             
        string connectionString =               
        @"DataSource=tcp:162.**.*.***;
        port=3306;
        Database=mysql_csharp;
        uid=root;
        password=***;";
        string query = "Insert into mysql_csharp.users   (firstname,lastname,message)values('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "');";## Heading ##
        MySqlConnection condb = new MySqlConnection(connectionString);
        MySqlCommand cmddb = new MySqlCommand(query, condb);
        MySqlDataReader myReader;

        try
        {
            condb.Open();
            myReader = cmddb.ExecuteReader();
            MessageBox.Show("Data Saved");
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            //this.BindGrid();
            while (myReader.Read())
            {

            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        this.Update();

Make sure your connection string for mysql is correct.If it's correct,just check whether you have an access to the server by connecting from your machine.

Following article will help you http://www.codeproject.com/Tips/423233/How-to-Connect-to-MySQL-Using-Csharp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM