C# MySql.Data.MySqlClient.MySqlException (0x80004005)
本文关键字:0x80004005 MySqlException MySqlClient MySql Data | 更新日期: 2023-09-27 18:13:32
这是我的连接字符串
"Server=xxx.xxx.xxx.x;Database=database;Uid='root';Pwd='';"
服务器上的ip是我想要访问的另一台计算机(有xampp)的ip。
这是我收到的异常。
MySql.Data.MySqlClient。MySqlException (0x80004005):无法连接到任意指定的MySQL主机。在MySql.Data.MySqlClient.NativeDriver.Open ()MySql.Data.MySqlClient.Driver.Open ()MySql.Data.MySqlClient.Driver.Create (MySqlConnectionStringBuilderMySql.Data.MySqlClient.MySqlPool.GetPooledConnection()mysql . data . mysqlclient . mysqlpool . trytotdriver (MySql.Data.MySqlClient.MySqlPool.GetConnection ()MySql.Data.MySqlClient.MySqlConnection.Open ()
使用c#的mysql,您不需要在连接字符串中使用单引号
,
ConnStr = "Server = XXX.XXX.XXX.XXX; Database = mydatabase; Uid = root; Pwd = yourpassword";
MySqlConnection con = new MySqlConnection(ConnStr)
您还可以验证您是否可以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; }
}
我认为你的连接字符串是错误的
我应该是In <appSettings>
In
<add key="myConnectionString" value="Server=localhost;Database=dbName;User Id=username;Password=password;"/>
或
in <connectionStrings>
<add name="myConnectionString" connectionString="Server=Server=localhost;Database=dbName;User Id=username;Password=password;" providerName="MySql.Data.MySqlClient"/>
以及参考此链接以启用Mysql的远程访问