Including SQLite DB file with data in the UWP application

entity-framework-core sqlite uwp windows-10

Question

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

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

So i have two questions:

  1. What is the correct way to bundle this file with the application.
  2. How do I compose the file path to access that file from UWP applciation?

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.

Thanks in advance!

1
1
7/27/2017 2:41:37 AM

Accepted Answer

My recommendation is ...

  1. Include the .db file to your AppX package. To include it, add the .db file to Assets folder in your project.
  2. Then, at the first time launch of your app, you should copy the .db file from Assets to your app's local folder. Because, SQLite itself can't access to the Assets folder. It can only access to the your app's local or temporary folder.

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

[UWP] SQLite.net Path question?

4
7/27/2017 5:59:54 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow