标题几乎说明了一切。当我尝试在我的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和密码都处于正常工作状态。
感谢您的帮助!