简体   繁体   中英

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. It works if i access the database using an app/website from the 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. 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" .

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修复了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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