.NET Core EF6错误与SQLite连接字符串

时间:2018-12-07 03:33:32

标签: c# entity-framework sqlite entity-framework-6

我似乎无法将参数传递给sqlite连接字符串...

如果我这样做:

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

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

一切正常。但是,如果我将其更改为:

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

然后查询抛出System.ArgumentException: 'Keyword not supported: 'version'.'

或者如果我将其更改为:

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

然后查询抛出System.ArgumentException: 'Keyword not supported: 'read only'.'

这是怎么了?我如何通过,即只读给sqlite?

1 个答案:

答案 0 :(得分:1)

根据所使用的提供商的不同,某些关键字不可用。您可以看一下https://www.connectionstrings.com/sqlite/的示例。如果您使用的是Microsoft.Data.Sqlite,则连接字符串应使用关键字 Mode = ReadOnly

来自this个报告的问题:

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
相关问题