“无法连接到任何指定的 MySQL 主机。”在智能设备项目 VS2008 中

发布于 2024-12-28 15:50:56 字数 1505 浏览 0 评论 0原文

我是智能设备项目的新手。我安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情徒 2025-01-04 15:50:56

我解决我的问题。希望这也对您有帮助。下面的代码非常适合我。

    DataSet ds = new DataSet();
    MySqlConnection conn = new MySqlConnection("server=server-ip;database=db-name;Character Set=utf8;Uid=user-name;password=****;");
    MySqlCommand cmd = new MySqlCommand("select * from table-name", conn);
    MySqlDataAdapter da = new MySqlDataAdapter();
    conn.Open();
    da.SelectCommand = cmd;
    da.Fill(ds);
    dataGridView1.DataSource = ds.Tables[0];
    conn.Dispose();
    cmd.Dispose();

I solve my problem. Hope this helps you too. Code below is working perfectly for me.

    DataSet ds = new DataSet();
    MySqlConnection conn = new MySqlConnection("server=server-ip;database=db-name;Character Set=utf8;Uid=user-name;password=****;");
    MySqlCommand cmd = new MySqlCommand("select * from table-name", conn);
    MySqlDataAdapter da = new MySqlDataAdapter();
    conn.Open();
    da.SelectCommand = cmd;
    da.Fill(ds);
    dataGridView1.DataSource = ds.Tables[0];
    conn.Dispose();
    cmd.Dispose();
和我恋爱吧 2025-01-04 15:50:56

我认为您的问题可能是由于智能设备连接外部网络的方式造成的。我认为您正在尝试使用模拟器从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文