我是智能设备项目的新手。我安装了 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
它是一个有效的连接字符串。所以数据库服务器用户名、密码都是正确的。没有问题。但我不明白为什么它只通过智能设备项目上的错误。
下面给出的代码。
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;
但没有用。