Unable to connect to any of the specified mysql hosts. C# MySQL

后端 未结 15 1463
庸人自扰
庸人自扰 2020-11-29 07:11

I am getting the above error when I execute the code -

MySqlConnection mysqlConn=new MySqlConnection(\"server=127.0.0.1;uid=pankaj;port=3306;pwd=master;datab         


        
15条回答
  •  无人及你
    2020-11-29 07:14

    I found the solution to my problem, I was having the same issue. Previously I had my connection string as this notice the port :3306 needs to be either attached to the server like that 127.0.0.1:3306 or removed from server like that Server=127.0.0.1;Port=3306 depending on your .NET environment:

    "Server=127.0.0.1:3306;Uid=username;Pwd=password;Database=db;"
    

    It was running fine until something happened which I am not sure exactly what it is, might be a recent update to my .NET application packages. It looks like format and spacing of the connection string is important. Anyways, the following format seems to be working for me:

    "Server=127.0.0.1;Port=3306;Uid=username;Pwd=password;Database=db;"
    

    Try either of the versions and see which one works for you.

    Also I noticed that you are not using camel casing, this could be it. Make sure your property names are in capital casing like that

    Server
    Port
    Uid
    Pwd
    Database
    

提交回复
热议问题