MySQL 连接器无法打开
我在这里进行了一个应该是微不足道的测试,但它顽固地拒绝工作。在“打开”时,会抛出异常“无法连接到任何指定的 MySQL 主机”。
MySQL.Data 是版本 6.4.4.0,在我的 Visual Studio 项目中引用,该项目构建时没有错误。 MySQL 版本为 5.5.16。该测试是使用带有 Windows 窗体的 Visual Studio 2008 构建的,并通过按钮启动,
我已经在 Windows XP 和 Windows 7 下的不同机器上进行了尝试。我收集自 允许的文档在连接字符串中使用 PASSWORD、PWD、UID、用户名、UserName、SERVER、HOST 以及关键字的多种变体,我已经尝试过所有这些,但都没有成功。
我确信我的用户名、密码和主机名是正确的。我可以使用相同的用户名和密码通过命令行连接到本地 MySQL 数据库。
using MySql.Data.MySqlClient;
// and the ususal MS stuff...
private void ToMySQL()
{
MySqlConnection myCon = new MySqlConnection("DataSource=Localhost;Username=root;Password=xxxx;database=data_xxx");
try
{
myCon.Open();
MessageBox.Show("OK");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这些事情通常被证明是完全微不足道的事情,但如果是这样的话,它是如此微不足道,以至于对我来说是看不见的。
我错过了什么?
编辑附录:到目前为止,除了一个例外(npi)之外,答案重复了失败的内容。如果问题是环境问题,我应该去哪里寻找?
I have what should be a trivial test here that is stubbornly refusing to work. On "Open" an exception "Unable to connect to any of the specified MySQL hosts" is thrown.
MySQL.Data is Version 6.4.4.0 and is referenced in my visual studio project, which builds without errors. MySQL is V 5.5.16. The test is built using Visual Studio 2008 with Windows Forms and and is launched via a Button,
I have tried this both under Windows XP and Windows 7, on different boxes. I gather from
the documentation that it is permissible to use PASSWORD, PWD, UID, User Name, UserName, SERVER, HOST, and numerous variations on the keywords in the connection string, and I have tried them all with equal lack of success.
I am confident that my username, password, and host name are correct. I am able to connect to my local MySQL DB via the command line using the same username and password.
using MySql.Data.MySqlClient;
// and the ususal MS stuff...
private void ToMySQL()
{
MySqlConnection myCon = new MySqlConnection("DataSource=Localhost;Username=root;Password=xxxx;database=data_xxx");
try
{
myCon.Open();
MessageBox.Show("OK");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
These things usually turn out to be something totally trivial, but if so it's so trivial that it's invisible to me.
What have I missed?
Edit-Addendum: Answers so far have with one exception (npi) duplicated what fails. If the problem is environmental, where might I look?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这个连接字符串 -
更改所有 <...>价值观。
Try this connection string -
Change all <...> values.