0

i need to connect to the other machine's mysql server using C# coding,below is my coding:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace c_mysql
{
    class Program
    {
        static void Main(string[] args)
        {
            string connection = "SERVER=192.168.1.5; Database=b2b; Uid=root;";
            MySqlConnection con = new MySqlConnection(connection);
            con.Open();
            MySqlCommand cmd = new MySqlCommand("select * from area",con);
            MySqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Console.WriteLine("connection successfull");
            }
            else
            {
                Console.WriteLine("not connected...");
            }
        }
    }
}

the ip address 192.168.1.5 is the ip address of other computer which is in LAN,I am able to connect through 192.168.1.5/phpmyadmin in url bar but when connecting through C# coding it says,

Host 'pc1' is not allowed to connect to this MySQL server

Pc 1 is my pc on which i am coding.

please help me.

Dinesh Suthar
  • 853
  • 1
  • 17
  • 41

1 Answers1

0

Enable Remote Root Access to MySql. click here for more details

Snippet taken from above:

create a new HOST for root and allow root to login from anywhere.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit
Mitz
  • 561
  • 8
  • 21