在UWP应用程序中包括SQLite DB文件和数据 [英] Including SQLite DB file with data in the UWP application

查看:62
本文介绍了在UWP应用程序中包括SQLite DB文件和数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在UWP应用程序中包含一个SQLite文件.SQLite文件中有许多填充数据的表.

I'm trying to include a SQLite file with the UWP application. SQLite file has a number of tables in it populated with data.

该数据库(至少目前为止)是只读的,我正计划使用EF Core访问数据.

The database (for now, at least) is read-only and I'm planning to use EF Core to access the data.

所以我有两个问题:

  1. 将此文件与应用程序捆绑在一起的正确方法是什么.
  2. 如何编写文件路径以从UWP应用访问该文件?

将.sqlite文件的复制到输出目录"设置设置为始终复制"似乎会将文件复制到bin文件夹,但是我似乎无法弄清楚访问它的路径.将SQLite连接字符串设置为"Filename = databasename.sqlite"时-似乎在其他地方创建了一个空白的DB文件,因为尝试访问任何表都会引发未找到表的异常.

Setting .sqlite file's "Copy to output directory" setting to "Copy always" seems to copy the file to bin folder but I can't seem to figure out the path to access it. When setting the SQLite conenction string to "Filename=databasename.sqlite" - it seems to create a blank DB file elsewhere, as tryign to access any of the tables throws a table not found exception.

提前谢谢!

推荐答案

我的建议是...

  1. 将.db文件包括到您的AppX包中.要包含它,请将.db文件添加到项目中的Assets文件夹中.
  2. 然后,在首次启动应用程序时,应将.db文件从Assets复制到应用程序的本地文件夹.因为,SQLite本身无法访问Assets文件夹.它只能访问您应用的本地或临时文件夹.

我已经在MSDN论坛上回答了类似的问题.也请参考.

I've answered for the similar question on MSDN forum. Please refer it too.

[UWP] SQLite.net路径问题吗?

这篇关于在UWP应用程序中包括SQLite DB文件和数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆