0

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 ?

2
  • 1
    What database provider are you using?
    – Garett
    Dec 7, 2018 at 19:48
  • how do I know which provider I am using ?? I do not have any using statement for Microsoft.Data.Sqlite ... I just used UseSqlite()
    – kofifus
    Dec 8, 2018 at 1:44

1 Answer 1

1

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
  • The provider I use is Microsoft.EntityFrameworkCore.Sqlite, I couldn't find relevant documentation but "Mode=ReadOnly;" worked ! thx
    – kofifus
    Dec 8, 2018 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.