我在机器上安装了mysql
我安装了GenyMotion Android Emulator
我在我的Xamarin App中使用Xamarin MySQL Connector。
如何从Genymotion中运行的Xamarin App连接到mysql数据库?
注意使用127.0.0.1作为IP地址将无法正常工作。
答案 0 :(得分:0)
您的应用不应直接与数据库服务器通信。通过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地址