简体   繁体   English

无法连接到任何指定的mysql主机。 C#

[英]unable to connect to any of the specified mysql hosts. c#

I've found many suggestions to fix this unprocessed exception, and I have tried every one I could find (and understand). 我已经找到了许多解决此未处理异常的建议,并且已经尝试了所有可以发现(并理解)的异常。 It's been hours, but still no results... I've created a windows forms application that asks for a client's information and I'm trying to Insert this info into a DB I have created in MySQL. 已经好几个小时了,但仍然没有结果...我创建了一个Windows窗体应用程序,该程序要求提供客户的信息,并且我试图将此信息插入在MySQL中创建的数据库中。 This is the code that seems to be working for everyone but me: 这是似乎适用于除我之外的所有人的代码:

public partial class Form1 : Form
{

    private MySqlConnection mConn;
    public Form1()
    {
        InitializeComponent();
        mConn = new MySqlConnection("Persist Security Info=False; server=localhost; database=xxxxxxx;uid=yyyyyyy;password=zzzzzzzz");
    }

    private void button1_Click(object sender, EventArgs e)
    {
        mConn.Open();
        if (mConn.State == ConnectionState.Open)
        {
            MySqlCommand command = new MySqlCommand("INSERT INTO client VALUES (" + textBox1.Text + ",' " + textBox2.Text + "', '" + textBox3.Text + "'," + textBox4.Text + ",' " + textBox5.Text + "')", mConn);
            command.ExecuteNonQuery();
            mConn.Close();
        }
        else
            MessageBox.Show("Connection Failed!");
    }
}

This is the exception text: 这是例外文本:

MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. MySql.Data.MySqlClient.MySqlException(0x80004005):无法连接到任何指定的MySQL主机。 ---> System.Net.Sockets.SocketException (0x80004005): The requested adress is not valid in this context [::1]:3306 in ... ---> System.Net.Sockets.SocketException(0x80004005):请求的地址在此上下文中无效[:: 1]:3306 in ...

If you can help me I'll be very grateful. 如果您能帮助我,我将不胜感激。 It's my first year programming and so far it has passed quite well, but now I have been "left behind" in my class because of this recurring error. 这是我的第一年编程,到目前为止还算不错,但是由于这个反复出现的错误,现在我在班上已经“落后”了。 Thank you in advance :) 先感谢您 :)

My Professor was able to find the problem. 我的教授能够找到问题所在。 For some reason my computer can't recognize the term localhost as the IP address 127.0.0.1, so when I was writing server = localhost in the connection string, an error occurred. 由于某种原因,我的计算机无法将术语localhost识别为IP地址127.0.0.1,因此当我在连接字符串中写入server = localhost时,发生了错误。 When I tried writing server = 127.0.0.1 everything worked smoothly. 当我尝试编写服务器= 127.0.0.1时,一切工作顺利。 I hope this is helpful. 我希望这是有帮助的。

Working connection string: 工作连接字符串:

"Persist Security Info=False;server=127.0.0.1;database=xx;uid=yy;password=zz"

The Problem with establishing connection to the remote site will be solved by providing public ip of that db instead of private one. 通过提供该数据库的公共IP而不是私有数据库,可以解决与远程站点建立连接的问题。

it will help u. 它会帮助你。 Try it. 试试吧。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到任何指定的 mysql 主机。 C# MySQL - Unable to connect to any of the specified mysql hosts. C# MySQL mySQL异常:无法连接到任何指定的MySQL主机。 通过C# - mySQL Exception: Unable to connect to any of the specified MySQL hosts. through C# :&#39;无法连接到任何指定的MySQL主机。 错误 - :'Unable to connect to any of the specified MySQL hosts.' error 无法连接到任何指定的MySQL主机。 - Unable to connect to any of the specified MySQL hosts. <add name=“MySqlSiteMapProvider” 错误“无法连接到任何指定的MySQL主机。” - ERROR “Unable to connect to any of the specified MySQL hosts.” 获取错误:“无法连接到任何指定的MySQL主机。”在不使用MySQL的应用程序中 - Getting error: “Unable to connect to any of the specified MySQL hosts.” In an application that doesn't use MySQL 仅在发布后出现错误:“无法连接到任何指定的MySQL主机。” - Error only occurs after publishing: “Unable to connect to any of the specified MySQL hosts.” 处理映射的网络驱动器将引发“无法连接到任何指定的MySQL主机。”异常 - Working off mapped network drive throws “Unable to connect to any of the specified MySQL hosts.” exception “无法连接到任何指定的MySQL主机。”在智能设备项目VS2008中 - “Unable to connect to any of the specified MySQL hosts.” in Smart Device Projects VS2008 无法以C#Windows形式连接到任何指定的MySQL主机 - Unable to connect to any of the specified MySQL hosts in c# windows form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM