加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 无法在SQLite的连接字符串中提供密码

发布时间:2020-12-15 23:33:25 所属栏目:百科 来源:网络整理
导读:我使用SQLite和Entity Framework. 我使用以下代码创建数据库: class MyContext : DbContext{ // DbSets,OnModelCreating(),etc. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlite("Data Source=
我使用SQLite和Entity Framework.

我使用以下代码创建数据库:

class MyContext : DbContext
{   
    // DbSets,OnModelCreating(),etc.

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlite("Data Source=c:test.db");
    }
}

//this is in my test method
 using (var db = new MyContext())
{
    db.Database.EnsureCreated();
}

上面的代码有效.数据库被创建.
但我想通过在连接字符串中提供密码来加密数据库:

optionsBuilder.UseSqlite("Data Source=c:test.db;Password=mypassword");

在这种情况下,在调用EnsureCreated之后,我得到异常

An unhandled exception of type ‘System.ArgumentException’ occurred in System.Data.dll
Additional information: Keyword not supported: ‘password’.

使用密码有什么问题?如何加密SQLite数据库?

解决方法

根据这个答案 Protect SQLite database used by EntityFramework Core Application

EF Core uses Microsoft.Data.Sqlite,which does not currently support
encryption out-of-box. See
07001. You could
add encryption yourself using SQLite extensions.

在提供的GitHub链接中,还有其他链接可供选择

Encryption in Microsoft.Data.Sqlite

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读