我的数据库在线,即 Cheapitservice.com。 Mysql 连接器产生如下错误:
Unable to connect to any of the specified MySQL hosts
我的代码是:
dbConn.ConnectionString = "Server=......hostedresource.com;Database=sampledb;user=user;password=test;"; dbConn.Open();
我的代码有问题吗?请帮助我。
mySQLconnector 版本为 6.6.5
最佳答案
您可以使用此链接使您的代码正常工作... ConnectionsString有了这个你就可以意识到出了什么问题......
示例:
static void Main(string[] args)
{
var ConnectionString = @"server=localhost; user=root; password=a54321; database=Prueba";
using (MySqlConnection con = new MySqlConnection(ConnectionString))
{
con.Open();
using (MySqlCommand Command = new MySqlCommand("SELECT IdEmpleado, Nombres, Apellidos, Correo, Telefono FROM Empleados", con))
using (MySqlDataReader Reader = Command.ExecuteReader())
{
while (Reader.Read())
{
Console.WriteLine("{0} - {1} - {2} - {3} - {4}",
Reader.GetInt32(0), Reader.GetString(1), Reader.GetString(2), Reader.GetString(3), Reader.GetString(4));
}
}
}
Console.ReadKey();
}
问候
关于Mysql .NET 连接字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21583063/