简体   繁体   English

C#UWP-如何将Mobile Emulator连接到本地MySQL数据库?

[英]C# UWP - How to connect Mobile Emulator to a local MySQL Database?

I'm trying to connect my Emulator app to a MySQL Database i created. 我正在尝试将模拟器应用程序连接到我创建的MySQL数据库。 It works if i access the database using an app/website from the LAPTOP . 如果我使用来自LAPTOP的应用程序/网站访问数据库,那么它将起作用。 But it fails to recognize the database if i am accessing it using the EMULATOR , my guess it that it treats the Windows Emulator as an external device. 但是,如果我使用EMULATOR访问数据库,它将无法识别数据库,我猜它会将Windows Emulator视为外部设备。 I already added Port 3306 (Default MySQL Port) in the firewall exceptions, freed database privileges, and used the IP Address of the Laptop and Emulator, and still, i get the "Cannot connect to any of the specified MySQL Hosts" . 我已经在防火墙例外中添加了端口3306(默认MySQL端口),释放了数据库特权,并使用了Laptop和Emulator的IP地址,但仍然出现了“无法连接到任何指定的MySQL主机”的信息

DB Connection Code: 数据库连接代码:

private async void dbConnectAsync()
    {
        string con = "server=192.168.8.100:3306;database=donation;uid=root;password=;SslMode=none;CharSet=utf8";
        MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder(con);
        using (conn = new MySqlConnection(con))
            try
            {
                conn.Open();
            }
            catch (Exception err)
            {
                var dialog2 = new MessageDialog(err.Message);
                dialog2.Title = "Connection Error";
                dialog2.Commands.Add(new UICommand { Label = "Ok", Id = 0 });
                var res = await dialog2.ShowAsync();
            }
    }

使用主机PC的IP地址192.168.8.100修复了该问题,并删除了:3306修复了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM