我的数据库在线是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
答案 0 :(得分:0)
您可以使用此链接为您的代码制作代码... 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();
}
此致