无法将C#程序连接到mySQL数据库

时间:2018-01-21 10:53:46

标签: c# mysql database

对于我的程序,我想使用mySQL作为数据的存储,这些数据将在那里导出并被用户看到。在这里,我宣布了两者之间的联系:

        string MyConnection2 = "server=localhost;database=leaderboard;user=root;password=root";

        MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
        string Query = "insert into leaderboard.leaderboard(Name,Score,Lives, Time) values('" + nameText.Text + "','" + "','" + scoreLabel.Text + "','" + livesText.Text + "','" + timeText.Text + "');";
        MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
        MySqlDataReader MyReader2;
        MyConn2.Open();
        MyReader2 = MyCommand2.ExecuteReader();

        if (MyConn2.State == ConnectionState.Open)
        {
            MessageBox.Show("Connection established!");
        }
        else
        {
            MessageBox.Show("No connection established");
        }

但是,当我在调试过程中尝试使用此表单时,会出现此错误:

  SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:3306

造成这种情况的原因是什么?

0 个答案:

没有答案