[英]C# MySql.Data.MySqlClient.MySqlException (0x80004005)
here's my connection string这是我的连接字符串
"Server=xxx.xxx.xxx.x;Database=database;Uid='root';Pwd='';"
the ip on the server is the ip of the other computer(have xampp) that I want to access.服务器上的ip是我要访问的另一台计算机(有xampp)的ip。
this is the Exception I receive.这是我收到的异常。
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
MySql.Data.MySqlClient.MySqlException (0x80004005):无法连接到任何指定的 MySQL 主机。 at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.Driver.Open() at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open()
在 MySql.Data.MySqlClient.NativeDriver.Open() 在 MySql.Data.MySqlClient.Driver.Open() 在 MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder 设置) 在 MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()在 MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() 在 MySql.Data.MySqlClient.MySqlPool.GetConnection() 在 MySql.Data.MySqlClient.MySqlConnection.Open()
With mysql on C# you don't need single quote in the connexion string使用 C# 上的 mysql,您不需要在连接字符串中使用单引号
Ex :前任 :
ConnStr = "Server = XXX.XXX.XXX.XXX; Database = mydatabase; Uid = root; Pwd = yourpassword";
MySqlConnection con = new MySqlConnection(ConnStr)
You can also verify that you can ping the other computer :您还可以验证是否可以 ping 另一台计算机:
using System.Net.NetworkInformation;
public static bool IsConnectedToServer()
{
Ping p = new Ping();
try
{
PingReply reply = p.Send("XXX.XXX.XXX.XXX", 3000);
if (reply.Status == IPStatus.Success)
return true;
else return false;
}
catch { return false; }
}
I think your connection string is wrong我认为你的连接字符串是错误的
I should be In <appSettings>
in我应该在
<appSettings>
中
<add key="myConnectionString" value="Server=localhost;Database=dbName;User Id=username;Password=password;"/>
or或者
in <connectionStrings>
在
<connectionStrings>
<add name="myConnectionString" connectionString="Server=Server=localhost;Database=dbName;User Id=username;Password=password;" providerName="MySql.Data.MySqlClient"/>
As well as Refer this Link to Enable Remote Access for Mysql以及请参阅此链接以启用 Mysql 的远程访问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.