c# - 如何从 Genymotion 连接到 MySql

标签 c# mysql xamarin genymotion

我在机器上安装了mysql。
我安装了 GenyMotion Android 模拟器
我在 Xamarin 应用程序中使用 Xamarin MySQL 连接器。 如何从 Genymotion 中运行的 Xamarin 应用程序连接到 mysql 数据库?

请注意,由于显而易见的原因,使用 127.0.0.1 作为 IP 地址是行不通的。

最佳答案

您的应用不应直接与数据库服务器通信。通过 API 是更好的方法。

现在我们已经解决了这个问题,这是一个取自 here 的简短示例。 :

try
{
    string connectionString = "Server=your.ip.address;Port=3306;database=YOUR_DATA_BASE;User Id=root;Password=password;charset=utf8";
    MySqlConnection  sqlconn = new MySqlConnection(connectionString);
    sqlconn.Open();
    string queryString = "select count(0) from ACCOUNT";
    MySqlCommand sqlcmd = new MySqlCommand(queryString, sqlconn);
    String result = sqlcmd.ExecuteScalar().ToString();
    // do something  with the results
    sqlconn.Close();
} catch (Exception ex)
{
    Console.WriteLine (ex.Message);
}

您应该能够从 GenyMotion(使用 VirtualBox)创建的虚拟网络适配器获取要使用的 IP 地址

关于c# - 如何从 Genymotion 连接到 MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37271692/

相关文章:

c# - 在 Xamarin Android 中存储 SQLite 数据库的路径

c# - 带有 TabbedView 的 Xamarin.Forms MasterDetailPage - 通过汉堡菜单导航时出现的选项卡标题

c# - Convert.ToDateTime() 错误

c# - 排序后变量为空

c# - 为 T-SQL 字符串文字正确的字符串转义

mysql - 如何在 ionic 4 客户端应用程序和 Express 服务器之间建立连接?

mysql - 如何将两个查询转换为 INT 并比较它们?

mysql - 如何将数据从一个 SQL 列表复制到另一个 SQL 列表

c# - 如何在 Xamarin iOS 中创建垂直 ScrollView

c# - 如何更改菜单栏中的 Xamarin 后退按钮?