C#MySql.Data.MySqlClient.MySqlException(0x80004005) [英] C# MySql.Data.MySqlClient.MySqlException (0x80004005)
问题描述
这是我的连接字符串
"Server=xxx.xxx.xxx.x;Database=database;Uid='root';Pwd='';"
服务器上的ip是我要访问的另一台计算机(具有xampp)的ip.
the ip on the server is the ip of the other computer(have xampp) that I want to access.
这是我收到的异常.
MySql.Data.MySqlClient.MySqlException(0x80004005):无法连接 到任何指定的MySQL主机.在 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()
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. 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()
推荐答案
在C#上使用mysql,在连接字符串中不需要单引号
With mysql on C# you don't need single quote in the connexion string
例如:
ConnStr = "Server = XXX.XXX.XXX.XXX; Database = mydatabase; Uid = root; Pwd = yourpassword";
MySqlConnection con = new MySqlConnection(ConnStr)
您还可以验证是否可以ping另一台计算机:
You can also verify that you can ping the other computer :
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; }
}
这篇关于C#MySql.Data.MySqlClient.MySqlException(0x80004005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!