无法连接到任何指定的mysql主机 [英] Unable to connect to any of the specified mysql host

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

问题描述

我正在将Visual Studio 2010与mySql服务器一起使用,工作台中的连接正常工作,但是当我尝试在应用程序中连接mysql时,会出现上述错误.
背后的原因是什么?

我正在使用以下连接字符串进行连接,
和下面的代码来使用它,

I am using visual studio 2010 with mySql server , the connection in workbench is working properly but when i am trying to connect mysql in my application , it gives above error.
what is the reason behind it?

I am using following connection string to connect,
and below code to use it,

con.ConnectionString = @"server=localhost;database=his_db;Uid=root;Pwd=root;persistsecurityinfo=True";


代码:


code:

cmd = new MySqlCommand("select distinct from_store_name from indent_details", con);
table = new DataTable();
adapter = new MySqlDataAdapter(cmd);
adapter.Fill(table);

foreach (DataRow row in table.Rows)
{
    string frmstore = row["from_store_name"].ToString();
    txtfromstore.Items.Add(frmstore);
}

推荐答案

可能是您需要重新创建连接字符串:可能是"localhost"不是您PC上的正确名称.

尝试使用服务器资源管理器"窗格在VS中建立连接:
1)打开服务器资源管理器.
2)右键单击数据连接",然后选择添加连接"
3)在随后的对话框中,选择您的数据源和数据库,指定安全信息,然后按测试连接"按钮.
4)连接正常后,按确定"
5)在服务器资源管理器"窗格中突出显示您的数据库,然后查看属性"窗格.将显示一个连接字符串的工作示例,您可以将其复制并粘贴到您的应用程序或配置文件中.
The chances are that you need to remake your connection string: it may be that "localhost" is not the right designation from your PC.

Try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.


Server = localhost; port = 3306; pooling = false; Database = DBname ; uid = root; pwd =;
Server=localhost;port=3306;pooling=false;Database=DBname;uid=root;pwd=";


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

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