A Microsoft platform for building and publishing apps for Windows devices.
Hi,
Welcome to Microsoft Q& A!
UWP Sqlite connection does not support folders other than application folder and local app folder.
UWP apps are running in the sandbox and when you run them they are installed into it. They are not running in your source code bin folder of your project. In order to make your code up and running, you need to add your db file to your project Assets folder, then set Build Action of this file to Content. The good thing is that your file is now included to your Installed app folder. The bad thing is that it is read only. It cannot perform operations, such as inserting data. To overcome it you need to copy it to local app folder, as follows:
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
string targetDbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Database\\Test1.db");
if (!File.Exists(targetDbPath))
{
var installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
using (var input = await installedLocation.OpenStreamForReadAsync("Assets\\Test1.db"))
{
using (var output = await Windows.Storage.ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync("Database\\Test1.db", Windows.Storage.CreationCollisionOption.FailIfExists))
{
await input.CopyToAsync(output);
}
}
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.