Skip to content

SQLite database created in wrong directory in packaged desktop app. #24213

Closed

Description

When using SQLite with EfCore under UWP, new SQLite databases are created in ApplicationData.Current.LocalFolder, in other words [user]\AppData\Local\Packages\[package number]\LocalState.

However, when I compiled my program as a packaged desktop app, the SQLite database was then created in [user]\AppData\Local\VirtualStore\Windows\SysWOW64. I am using WinUI 3 preview 4 with .NET 5 and VS 16.9.0 preview 4, and I created my app with the "Blank App, Packaged (WinUI in Desktop)" template that comes with the WinUI 3 preview 3 extension. I am creating my database using EnsureCreatedAsync() and I am using Microsoft.EntityFrameworkCore.Sqlite v5.0.3.

You may recall that #19754 and #19468 were earlier bugs in which EF did not initialize the SQLite directory. The workaround was to insert the following lines prior to using SQLite:

const int dataDirectoryType = 1;
const int tempDirectoryType = 2;
SQLitePCL.Batteries_V2.Init();
SQLitePCL.raw.sqlite3_win32_set_directory( dataDirectoryType, Windows.Storage.ApplicationData.Current.LocalFolder.Path);
SQLitePCL.raw.sqlite3_win32_set_directory( tempDirectoryType, Windows.Storage.ApplicationData.Current.TemporaryFolder.Path);

When I applied this workaround to my packaged desktop app, the SQLite database was then created in ApplicationData.Current.LocalFolder.

P.S. See also Eric Sink's entry in the SQLite repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions