MySQL的异常:无法连接到任何指定的MySQL主机。通过C# [英] mySQL Exception: Unable to connect to any of the specified MySQL hosts. through C#

查看:2264
本文介绍了MySQL的异常:无法连接到任何指定的MySQL主机。通过C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

strProvider =数据源= 184.67.33.33;数据库= ABCD;用户ID = ABCD;密码= 12345678
不工作以及

strProvider =数据源= 184.67.33.33;初始目录= ABCD;用户ID = ABCD;密码= 12345678
也不能正常工作。

提示错误在 objmycon.Open()

我使用上面的字符串作为我的连接​​字符串,它给MySQL的异常

我无法找到任何一点毛病this.But仍然给出错误

有什么地方出错了?


解决方案

有可能有一些原因是什么问题。


  1. 检查您的主机文件。 (转到运行菜单和以往+ <大骨节病>输入 %SYSTEMROOT%\\ SYSTEM32 \\ drivers \\ etc下\\ 打开Notepad.exe的管理员模式和编辑<强>主机文件。)

它应该有

 #本地主机名称解析的DNS本身内部处理。
    127.0.0.1本地主机:: 1本地主机


  1. 很有可能您正在使用的一些端口连接到MySQL。所以,你必须包含端口号到连接字符串。

https://www.connectionstrings.com/mysql/

因此​​,它应该像

 服务器= myServerAddress;端口= 1234;数据库= MyDatabase的; UID =名为myUsername;
PWD = MYPASSWORD;

通常港 3306 所以一定要小心你是什么样的一个MySQL端口号输入。

strProvider = "Data Source=184.67.33.33;Database=abcd;User ID=abcd;Password=12345678" is not working and

strProvider = "Data Source=184.67.33.33;Initial Catalog=abcd;User ID=abcd;Password=12345678" is also not working.

it gives error at objmycon.Open()

I am using above string as my connection String and it gives mySQL Exception

I am not able to find any thing wrong with this.But still gives error

what could be wrong?

解决方案

There could be some reasons for that issue.

  1. Check your hosts file. (Go to Run menu and past+enter %systemroot%\system32\drivers\etc\. Open Notepad.exe in Administrator mode and edit hosts file.)

It should have

# localhost name resolution is handled within DNS itself.
    127.0.0.1       localhost   ::1             localhost

  1. Very probably that you are using some Port to connect to MySQL. So you have to include Port number into connection string.

https://www.connectionstrings.com/mysql/

So it should like

Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;

Usually Port is 3306 so be careful what you are input like a MySQL Port number.

这篇关于MySQL的异常:无法连接到任何指定的MySQL主机。通过C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆