Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0] Microsoft.Data.Sqlite: Also try the .NET 5+ ApplicationData API #26114

Merged
merged 1 commit into from
Sep 22, 2021

Conversation

bricelam
Copy link
Contributor

@bricelam bricelam commented Sep 20, 2021

We have code for UWP that sets the SQLite data and temp directories so that databases can be created when running inside an app container sandbox. .NET 5 added new bindings for WinRT APIs, and our code no longer ran on .NET 5/6 apps requiring users to manually set the SQLite directories.

Fixes #24213

/cc @Pilchie

Customer impact

Without this, the experience of using SQLite in MSIX-packaged windows apps would continue requiring additional, non-obvious steps.

Regression

Not in .NET 6, but the experience was regressed going from UWP to MSIX-packaged .NET 5 apps.

Testing

We don't have any automated tests that run inside of a sandboxed app container. Manually verified that databases are now created correctly. (using winsqlite3.dll)

Risk

Low. We're just probing for one additional assembly; if it fails, execution continues the same as when we didn't find the UWP API.

@bricelam bricelam requested a review from a team September 20, 2021 22:00
@bricelam

This comment has been minimized.

@bricelam

This comment has been minimized.

@bricelam
Copy link
Contributor Author

bricelam commented Sep 21, 2021

Updated to continue on errors

@@ -34,12 +35,12 @@ public static void Initialize()
var rc = sqlite3_win32_set_directory(
SQLITE_WIN32_DATA_DIRECTORY_TYPE,
ApplicationDataHelper.LocalFolderPath);
SqliteException.ThrowExceptionForRC(rc, db: null);
Debug.Assert(rc == SQLITE_OK);
Copy link
Contributor Author

@bricelam bricelam Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Changed to asserts since the wrong version of a SQLitePCLRaw assembly gets deployed with the new net5.0-windows TFM, so the API returns SQLITE_ERROR. It's safe to ignore errors here, since the worst thing that can happen is relative paths are resolved to a directory without write permissions, and the error message they get later when trying to open the connection will be a lot more useful anyway.

@Pilchie
Copy link
Member

Pilchie commented Sep 22, 2021

Approved for EFCore 6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQLite database created in wrong directory in packaged desktop app.
3 participants