【发布时间】:2012-01-25 20:29:43
【问题描述】:
我正在使用带有 Visual Studio、C# 的 MySQL,并且我已经添加了所需的资源。我的代码是:
使用 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;
}
}
但我在 UnableToGetAllItems 异常中收到“无法连接到任何指定的 MySQL 主机”消息框。虽然我确信我在 000webhost CPanel 的 Manage MySQLDatabases 页面上输入了完全相同的主机名。为什么会这样?
【问题讨论】:
-
看起来这是一个托管的 MySQL 机器?所需的端口是否打开?
标签: c# mysql visual-studio connection