Mysql .NET 连接字符串错误

标签 mysql

我的数据库在线,即 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/

相关文章:

mysql - 在 OSX 10.6 开发机器上运行 mysql 时遇到问题 : "ERROR 2002 (HY000): Can' t connect to local MySQL server through socket '/tmp/mysql.sock' (2)"

php - 使用 MySql php 计算循环字段

mysql交集,比较,UNION的对立面?

mysql - 如何修改数据库字段来更改所有产品的 magento 1 税费?

php - foreach循环问题中的CakePHP多个数据库连接

mysql - sql - 随机选择一行并更新它

mysql - 在 Mac OS X 10.5 上,mysql 数据库文件位于何处

javascript - 为什么 date_format(? ,'%d-%b-%y' ) 在 Node 中失败?

python - 填充 Pandas 中缺失的 bool 行

java - 莫名其妙的连接泄漏导致 webapp 崩溃