.Net core application with EFCore using Sqlite DB on linux giving error "Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 14: 'unable to open database file'."

Hrushikesh Patel 0 Reputation points
2024-06-27T05:27:57.4366667+00:00

I'm running a simple .Net Core application on Linux using EFCore and SQLite, but I'm getting the following error:

An exception occurred while iterating over the results of a query for context type 'ApplicationDbContext'. Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 14: 'unable to open database file'.

The same code is working fine on Windows. Below is an excerpt from the code:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    if (!optionsBuilder.IsConfigured)
    {
        optionsBuilder.UseSqlite($"Data Source={DbPath}");
    }
}

DBPath is properly formed inside Linux, as the same path can read a normal text file. The only issue is with the SqliteDB file.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
717 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 59,806 Reputation points
    2024-06-27T16:03:28.85+00:00

    if using vs code, install the sqlite plugin and validate the db file access. but most likely the path is wrong. also if the build is copying the db as content, be sure the permissions are correct.

    0 comments No comments