xamarin.forms - SQLite DB 创建后存储在 Desktop 中的位置
问题描述
我在 Visual Studio 2017 中使用以下代码在 Xamarin 表单中创建了一个 SQLite 数据库。
try
{
sqliteconnection = DependencyService.Get<ISQLite>().GetConnection();
sqliteconnection.CreateTable<MyClassModel>();
}
catch(Exception ex)
{
string strErr = ex.ToString();
}
在 Xamarin.Android 中:
public SQLite.Net.SQLiteConnection GetConnection()
{
string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
// Documents folder
var path = Path.Combine(documentsPath, DatabaseHelper.DbFileName);
var plat = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
var conn = new SQLite.Net.SQLiteConnection(plat, path);
// Return the database connection
return conn;
}
我已将数据添加到表中。如何取出数据库以检查是否有数据。
我使用这种方法:我的 PC 上的 C:\Users\user-name\AppData\Local 进行检查。
但找不到数据库。
请帮忙。
解决方案
SQLite 数据库存储在手机上,而不是您的电脑上。如果您的手机没有root,您将无法直接访问它。要在手机上访问它,您必须获得 root 访问权限,然后可以在data/data//files/ 下找到数据库。
要查看数据库架构,您可以将数据库从设备上拉下来并使用 SQLite 管理器工具来查看架构并浏览数据。一种简单的方法是在 Android 模拟器中启动应用程序。在模拟器仍在运行时,打开 Android SDK 命令提示符。在 Xamarin Studio 和 Visual Studio 中,有一个快捷方式可以从“工具”菜单启动它。在命令提示符下,键入:adb pull [完整路径和数据库文件名]。
您可以在调试应用程序时通过检查 SQLiteDatabase 对象的 Path 属性来获取路径。
示例: adb pull /data/data/<Your-Application-Package-Name>/databases/<your-database-name>
数据库将被复制到您机器上的 Android SDK 文件夹中。要查看复制到您机器上的 SQLite 数据库,您可以使用DB Browser for SQLite 之类的工具: http: //sqlitebrowser.org如果您使用的是 Visual Studio,您可以安装SQLite Toolbox 扩展,您可以从在 Visual Studio IDE 中管理 SQLite 数据库:http ://sqlcetoolbox.codeplex.com/ 。
推荐阅读
- c++ - 使用 atan2 将 - 1 到 1 的范围转换为度数
- playframework-2.6 - 如何使用消息文件创建自己的 messagesApi
- javascript - 如何根据类中的属性位置获取元素的具体名称
- php - 如何爬取链接使用相同的css
- javascript - event.stopPropagation() 在本机 HTMLElement 内的 ReactJS 组件上失败
- python - 根据指定列中的值将行插入数据框中
- iframe - 我们在 Google Analytics 中从我们拥有的、驻留在第三方网站上的嵌入式 iFrame 中捕获了哪些数据?
- android - 约束图像正在改变大小
- javascript - 创建 HTML 元素后如何调用 JavaScript 函数?
- java - 与 MVVM 的套接字连接