[英]unable to connect to other machine's mysql server using C#?
i need to connect to the other machine's mysql server using C# coding,below is my coding: 我需要使用C#编码连接到另一台机器的mysql服务器,以下是我的编码:
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, IP地址192.168.1.5是局域网中其他计算机的IP地址,我可以通过url栏中的192.168.1.5/phpmyadmin连接,但是通过C#编码连接时,
Host 'pc1' is not allowed to connect to this MySQL server
Pc 1 is my pc on which i am coding. PC 1是我正在编码的PC。
please help me. 请帮我。
Snippet taken from above: 从上方摘录的片段:
create a new HOST for root and allow root to login from anywhere. 为root创建一个新的HOST,并允许root从任何地方登录。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.