Efcore: SQLite: Unable to open database file with UWP

Created on 3 Jan 2020  路  3Comments  路  Source: dotnet/efcore


Passing Data Source=MyDatabase.db does not work anymore when calling DbContextOptionsBuilder.UseSqlite(string).

The exception thrown is :

An error occurred using the connection to database 'main' on server 'MyDatabase.db'.
Exception thrown: 'Microsoft.Data.Sqlite.SqliteException' in System.Private.CoreLib.dll
SQLite Error 14: 'unable to open database file'.

Previously, it put the specified database into the LocalState folder.

This has also been reported here, but the solution does not satisfy me as I code to get the current package LocalState folder.

Steps to reproduce

Create a basic UWP app with a DbContext and use the method UseSqlite("Data Source=MyDatabase.db"). Then try creating the database or use the Database.MigrateAsync method.

Further technical details

EF Core version: 3.1.0
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: UWP
Operating system: Windows 10
IDE: Visual Studio 2019 16.4

closed-external customer-reported

Most helpful comment

All 3 comments

Can we reopen this (or #19754) please or add some further explanation / discussion. The article linked by @bricelam is interesting but

(a) It means dropping down into raw SQLite, which seems like a design gap if we consider EFCore to be our database interface;

(b) I am not clear on when in the EF context creation / model construction process these calls should go;

(c) I am not sure how the directory specified in this manner interacts with a directory specified using "Filename=xxx" in DbContextOptionsBuilder.UseSqlite.

I know that in earlier EFCore versions, you could not specify the directory used for the SQLite database using the options builder. But that would be the logical way to do it in the EF setup, and given that it is no longer buried in SQLitePCLRaw maybe we should look at doing it in EF.

We're going to try fixing this (i.e. set it for you) in an upcoming 3.1 patch use #19754 to track our progress.

Was this page helpful?
0 / 5 - 0 ratings