无法连接到指定的mysql主机_无法连接到任何指定的mysql主机

本文讨论了在使用Visual Studio 2010与MySQL Server进行应用开发时遇到的连接错误问题。作者提供了具体的连接字符串和代码示例,并分享了一个有效的解决方案,包括如何设置正确的连接字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

bd96500e110b49cbb3cd949968f18be7.png

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);

}

解决方案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=";

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值