无法使用C#连接到任何指定的MySQL主机 [英] Unable to connect to any of the specified MySQL hosts using C#

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

问题描述

先生我正在创建与我的sql的连接我的代码是:



MySqlConnection con = new MySqlConnection(server = 50.62.22.158:8808; database = hello4 uid = root;密码= hello42 @ 3;);



MySqlCommand command = con.CreateCommand();

command.CommandText = select * from login;

con.Open();

MySqlDataReader Reader = command.ExecuteReader();

while(Reader.Read ())

{

string name =;

string pass =;

if(b) !Reader.IsDBNull(0))

name =(string)Reader [userName];

pass =(string)Reader [userPass];

}

MessageBox.Show(成功);

Reader.Close();





先生,当我使用本地服务器工作时



但是当我使用另一台服务器时,例如:50.62.22.158:8808

显示错误:

无法连接到任何指定的MySQL主人



先生请告诉我什么是我的字符串问题

Sir i am create connection with my sql my code is:

MySqlConnection con = new MySqlConnection("server=50.62.22.158:8808; database=hello4 uid=root; password= hello42@3;");

MySqlCommand command = con.CreateCommand();
command.CommandText = "select * from login";
con.Open();
MySqlDataReader Reader = command.ExecuteReader();
while (Reader.Read())
{
string name = "";
string pass = "";
if (!Reader.IsDBNull(0))
name = (string)Reader["userName"];
pass = (string)Reader["userPass"];
}
MessageBox.Show("success");
Reader.Close();


bt sir when i am using local server its work

but when i use another server e.g :50.62.22.158:8808
its show error :
Unable to connect to any of the specified MySQL hosts

sir please tell me whats is problem of my string

推荐答案

客户无法联系到服务器。您是否有内部例外情况可以为您提供更多细节?通常这是网络/防火墙问题。



还要考虑使用更多使用语句来确保资源得到充分处理。这与您的编程问题无关。
The client is unable to reach the server. Do you have inner exceptions that gives you more detail? Usually this is a network / firewall problem.

Also consider using more using statements to make sure resources are disposed adequately. This has nothing to do with your programming question tho.


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

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