.NET Core EF6 error with SQLite connection string

c# entity-framework entity-framework-6 sqlite

Question

I can't seem to pass parameters to sqlite connection string ...

If I do:

 public class MyDbContext : DbContext {
    public DbSet<MyData> MyData { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
      optionsBuilder.UseSqlite("Data Source=C:\\src\\mydb.db;");
    }
  }

Everything works fine. However if I change it to:

optionsBuilder.UseSqlite("Data Source=C:\\src\\mydb.db;Version=3;");

Then queries throw System.ArgumentException: 'Keyword not supported: 'version'.'

or if I change it to:

optionsBuilder.UseSqlite("Data Source=C:\\src\\mydb.db;Read Only=True;");

Then queries throw System.ArgumentException: 'Keyword not supported: 'read only'.'

what's wrong here ? how do I pass ie read only to sqlite ?

1
0
12/7/2018 3:33:31 AM

Accepted Answer

Depending of the provider you are using certain keywords are not available. You can take a look at https://www.connectionstrings.com/sqlite/ for examples.If you are using Microsoft.Data.Sqlite then the connection string should use the keyword Mode=ReadOnly

From this reported issue:

We support the following keywords.

Keyword Values
Cache   Private or Shared
Data Source The database file. Can be a URI filename.
Mode    ReadWriteCreate, ReadWrite, ReadOnly, or Memory
1
12/7/2018 7:55:23 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow