Referencing and reading from a .sqlite database file (C#/UWP) -
all i'm trying use .sqlite database file have stored in assets folder of app (/assets/commoncore.sqlite). i'm trying set connection , i've tried few different things:
sqlite.net.sqliteconnection conn; public mainpage() { this.initializecomponent(); conn = new sqlite.net.sqliteconnection("data source=assets/commoncore.sqlite");
but throws exception "does not contain constructor takes 1 arguments".
string path; sqlite.net.sqliteconnection conn; public mainpage() { this.initializecomponent(); path = path.combine(windows.storage.applicationdata.current.localfolder.path, "commoncore.sqlite"); conn = new sqlite.net.sqliteconnection(new sqlite.net.platform.winrt.sqliteplatformwinrt(), path);
but references folder "\appdata\local\packages\8ed84aca-896d-4286-ba91-e52316db2e89_dzc2ymb8n4xk4\localstate\commoncore.sqlite" isn't file need.
i'm sure it's silly i'm missing.
in uwp apps, folders can access limited:
- all files user specifies using fileopenpicker or folderpicker
- files futureaccesslist or mostrecentlyusedlist. futureaccesslist can declared in manifest file (e.g. documents, pictures, videos folder). however, user has allow access these folders.
- files opened file extension association or via sharing.
- the application install directory.
- the application data locations.
- in cases removable devices.
in case trying write application data locations. however, each time install app, folder empty.
an alternative read sqlite database install folder. easy add files project folder. this, first have declare files want package. means adding them install folder. first, create subfolder in work directory (the folder can find appxmanifest.xml). not necessary cleaner. i've called folder 'data'.
next can check if did correctly. open project in visual studio , click 'show files' button in solution explorer.
after that, should able see new folder , content in solution explorer. can right click on folder , select 'include in project'.
finally, should open properties of file (e.g. db.sqlite in data folder) , set build action content.
now can connect db using code:
public class database { string path; sqlite.net.sqliteconnection conn; public database() { path = path.combine(windows.applicationmodel.package.current.installedlocation.path, "data", "questions.sqlite"); conn = new sqlite.net.sqliteconnection(new sqlite.net.platform.winrt.sqliteplatformwinrt(), path); } }
Comments
Post a Comment