简体   繁体   English

具有SQLite异常的实体框架:底层提供程序在Commit上失败

[英]Entity Framework with SQLite exception: The underlying provider failed on Commit

I'm using the Entity Framework (.NET 4.0) with SQLite as the underlying database and I get an exception when I try to commit some changes to the database: 我正在使用实体框架(.NET 4.0)和SQLite作为底层数据库,当我尝试向数据库提交一些更改时,我得到一个异常:

The underlying provider failed on Commit. 提交时底层提供程序失败。

The stack trace is: 堆栈跟踪是:

System.Data.EntityException: The underlying provider failed on Commit. ---> System.Data.SQLite.SQLiteException: The database file is locked
database is locked
   at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
   at System.Data.SQLite.SQLiteDataReader.NextResult()
   at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavi
or behave)
   at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
   at System.Data.SQLite.SQLiteTransaction.Commit()
   at System.Data.EntityClient.EntityTransaction.Commit()
   --- End of inner exception stack trace ---
   at System.Data.EntityClient.EntityTransaction.Commit()
   at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
   at MySystem.MySystemService.UpdateFollowersAndUsers() in C:\Path\To\MySystem\MySystemService.cs:line 295

My code is pretty simple: 我的代码非常简单:

// Gets more followers for the competitor and updates the database
List<Follower> moreFollowers = GetMoreFollowers(competitor);

// Add the new followers to the database
using (MySystemEntities db = new MySystemEntities())
{
    try
    {
        foreach (Follower f in moreFollowers)
        {
            db.AddToFollowers(f);
        }
        db.SaveChanges();
    }
    catch (Exception e)
    {
        Console.WriteLine(e.ToString());
    }
}

This snippet of code is inside MyService , it comes in with a batch of 5,000 followers and it's getting the above exception. 这段代码在MyService ,它有一批5,000个粉丝,它得到了上述异常。 However, when I pull the same snippet of code out into the Main function and just manually add a few followers, then it no longer throws the exception and the followers are successfully added to my database. 但是,当我将相同的代码片段输出到Main函数中并且只是手动添加一些关注者时,它不再抛出异常并且关注者已成功添加到我的数据库中。 Apparently the database file is locked, what may be causing this issue? 显然数据库文件已被锁定,可能导致此问题的原因是什么?

I just found out the answer in another SO question: 'The database file is locked' with System.Data.SQLite 我刚刚在另一个SO问题中找到答案: '数据库文件被System.Data.SQLite锁定'

Ironically, the OP answers his own question too :). 具有讽刺意味的是,OP也回答了他自己的问题:)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架异常“底层提供程序打开失败” - Entity Framework Exception “The underlying provider failed on Open” SQLite&Entity Framework 6“基础数据提供程序无法打开” - SQLite & Entity Framework 6 “The underlying data provider failed to open” NServiceBus和实体框架导致异常-基础提供程序在打开时失败 - NServiceBus and Entity Framework causes exception - The underlying provider failed on Open 实体框架给出异常:“底层提供程序在打开时失败。” - Entity Framework giving exception : “The underlying provider failed on Open.” 实体框架 - ConnectionString 上的底层提供程序失败 - Entity Framework - The underlying provider failed on ConnectionString 基础提供程序无法打开-WPF和实体框架 - The underlying provider failed to open - WPF and Entity FrameWork 实体框架底层提供程序在打开时失败 - Entity Framework The underlying provider failed on Open 基础提供程序在实体框架中打开时失败 - The underlying provider failed on Open in entity framework connection 使用WEB API和Entity Framework Project的IIS本地计算机上的“基础提供程序无法打开”异常 - “The underlying provider failed to Open” exception on IIS Local Machine using WEB API and Entity Framework Project 在实体框架上下文中使用单例模式-基础提供程序在打开时失败 - Using singleton pattern with Entity Framework context - The underlying provider failed on open
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM