"无法连接到任何指定的MySql主机"通过C#连接时

时间:2016-01-27 23:57:48

标签: c# mysql

标题几乎说明了一切。当我尝试在我的Namecheap托管的Web服务器上连接到我的SqlServer时,它会抛出" Unable to connect to any of the specified MySql hosts"错误信息。

有什么想法吗?

using System;
using System.Windows.Forms;

using MySql.Data.MySqlClient;
using System.Threading;

namespace Voting
{
    public partial class Form1 : Form
    {
        public MySqlConnection connection;
        public string connectionString;

        public Form1()
        {
            InitializeComponent();
        }

        private void Connect_Click(object sender, EventArgs e)
        {
            Thread connectThread = new Thread(new ThreadStart(DatabaseConnect));

            connectThread.Start();
        }

        private void DatabaseConnect()
        {
            Connect.Text = "Loading";

            connectionString = "Server = mywebsiteishere; Port = 3306; Database = thisdatabase; Uid = mypassword; Password = myusername;";

            try
            {
                connection = new MySqlConnection();

                connection.ConnectionString = connectionString;

                connection.Open();
                MessageBox.Show("Connection Success!");
            }

            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }

            Connect.Text = "Connect";
        }
    }
}

我想注意,在connectionString变量中,服务器,数据库,UID和密码都处于正常工作状态。

感谢您的帮助!

0 个答案:

没有答案