“无法连接到任何指定的 MySQL 主机。”在智能设备项目 VS2008 中
我是智能设备项目的新手。我安装了 MySQL Connector Net 6.4.4。我在 vs 2008 中为 mysql 连接添加了 MySql.Data.CF。
但我无法获得输出。 “无法连接到任何指定的 MySQL 主机。” 通过 connection.open() 出现异常。
server=192.168.1.100;User Id=mcubic;Persist Security Info=True;database=mcubic
它是一个工作连接字符串。所以数据库服务器用户ID、密码是正确的。这没有问题。但我不明白为什么它仅通过智能设备项目上的错误。
下面给出的代码。
try
{
string connectionString = "server=192.168.1.100;User Id=mcubic;Persist Security Info=True;database=mcubic";
string query = "select b.Outlet_Master_Name from mcs_user_outlet a,outlet_master b where a.Mcs_User_Outlet_User_Id=3 and a.Mcs_User_Outlet_Outlet_Id = b.Outlet_Master_Id";
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand command = new MySqlCommand(query, connection);
connection.Open();
MySqlDataReader Reader = command.ExecuteReader();
while (Reader.Read())
{
comboBox1.Items.Add(Reader[0].ToString());
}
connection.Close();
}
catch(Exception ex)
{
MessageBox.Show(""+ex.Message);
}
帮我找出错误。
我已经尝试过下面的连接字符串。
server=192.168.1.100;UID=mcubic;Persist Security Info=True;database=mcubic
server=192.168.1.100;User Id=mcubic;Persist Security Info=False;database=mcubic
server=192.168.1.100;User Id=mcubic;Persist Security Info=False;Initial Catalog=mcubic;
server=192.168.1.100;UID=mcubic;Persist Security Info=True;database=mcubic;pooling = false;
但没有用。
I am new to Smart Device Projects. I installed MySQL Connector Net 6.4.4. And i add MySql.Data.CF for mysql connection in vs 2008.
But i can't get the output. "Unable to connect to any of the specified MySQL hosts." exception through on the connection.open().
server=192.168.1.100;User Id=mcubic;Persist Security Info=True;database=mcubic
its a working Connection string. So database server user id, password are correct. No issue in that. But i can't understand why it through error on Smart Device Projects only.
The code given below.
try
{
string connectionString = "server=192.168.1.100;User Id=mcubic;Persist Security Info=True;database=mcubic";
string query = "select b.Outlet_Master_Name from mcs_user_outlet a,outlet_master b where a.Mcs_User_Outlet_User_Id=3 and a.Mcs_User_Outlet_Outlet_Id = b.Outlet_Master_Id";
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand command = new MySqlCommand(query, connection);
connection.Open();
MySqlDataReader Reader = command.ExecuteReader();
while (Reader.Read())
{
comboBox1.Items.Add(Reader[0].ToString());
}
connection.Close();
}
catch(Exception ex)
{
MessageBox.Show(""+ex.Message);
}
Help me to find out the error.
I have tried below Connection Strings.
server=192.168.1.100;UID=mcubic;Persist Security Info=True;database=mcubic
server=192.168.1.100;User Id=mcubic;Persist Security Info=False;database=mcubic
server=192.168.1.100;User Id=mcubic;Persist Security Info=False;Initial Catalog=mcubic;
server=192.168.1.100;UID=mcubic;Persist Security Info=True;database=mcubic;pooling = false;
But No Use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决我的问题。希望这也对您有帮助。下面的代码非常适合我。
I solve my problem. Hope this helps you too. Code below is working perfectly for me.
我认为您的问题可能是由于智能设备连接外部网络的方式造成的。我认为您正在尝试使用模拟器从 Visual Studio 运行此程序。
我认为您需要先连接到 MySql 服务器所在的外部网络,然后再尝试连接到服务器本身。
有一个 这里的文章涵盖了您的问题,但涉及 SQL Server。我确信它会解决您遇到的相同问题。
I think that your problem may be due to the way in which Smart Devices connect to external networks. I take it that you're trying to run this from Visual Studio using an emulator.
I gather that you need to connect to the external network on which your MySql server resides before attempting to connect to the server itself.
There's an article here that covers your problem but with SQL Server. I'm sure that it would cover the same problem that your experiencing.