我正在使用MySQL使用Visual Studio,C#和我添加了所需的資源。我的代碼是:在Visual Studio中使用MySQL C#錯誤
using MySql.Data.MySqlClient;
string MySqlConnectionValues = "SERVER=blahblahblah.000webhost.com; DATABASE=dbdbdbdb;UID=OopsIDon'tRemember; PASSWORD=whatspassword?;";
MySqlConnection MySQLCon;
MySqlDataAdapter MySQLDataAdapter;
DataTable DTItems;
private void MySQLForm_Load(object sender, EventArgs e)
{
try
{
MySQLCon = new MySqlConnection(MySqlConnectionValues);
}
catch (Exception UnableToConnectToMYSQL)
{
MessageBox.Show(UnableToConnectToMYSQL.Message.ToString());
}
}
DataTable GetAllItems()
{
try
{
string Query = "select * from items";
MySQLDataAdapter = new MySqlDataAdapter(Query, MySQLCon);
DataSet DS = new DataSet();
MySQLDataAdapter.Fill(DS);
return DS.Tables[0];
}
catch (Exception UnableToGetAllItems)
{
MessageBox.Show(UnableToGetAllItems.Message.ToString());
return null;
}
}
但我得到「無法連接到任何指定的MySQL主機」消息箱UnableToGetAllItems異常。儘管我確信在000webhost CPanel中管理MySQLDatabases頁面上輸入的主機名完全相同。爲什麼會發生?
看起來這是一個託管的MySQL框?所需端口是否打開? – Stu