【问题标题】:.NET Core EF6 error with SQLite connection string.NET Core EF6 错误与 SQLite 连接字符串
【发布时间】:2019-05-08 19:47:16
【问题描述】:

我似乎无法将参数传递给 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'.'

这里有什么问题?如何将 ie read only 传递给 sqlite?

【问题讨论】:

  • 您使用的是什么数据库提供商?
  • 我如何知道我使用的是哪个提供商??我没有 Microsoft.Data.Sqlite 的任何 using 语句......我只是使用了 UseSqlite()

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


【解决方案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

【讨论】:

  • 我使用的provider是Microsoft.EntityFrameworkCore.Sqlite,找不到相关文档但是“Mode=ReadOnly;”工作!谢谢
猜你喜欢
  • 2016-10-02
  • 1970-01-01
  • 2017-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-05
  • 1970-01-01
  • 2019-01-07
相关资源
最近更新 更多