2016-05-17 44 views
0

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

注意使用127.0.0.1作为IP地址不起作用,原因很明显。

回答

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创建的虚拟网络适配器使用的IP地址(使用VirtualBox)