实体框架使用SQLite异常:基础提供失败的提交 [英] Entity Framework with SQLite exception: The underlying provider failed on Commit

查看:241
本文介绍了实体框架使用SQLite异常:基础提供失败的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是实体框架(.NET 4.0)与SQLite作为底层数据库,当我尝试提交了一些对数据库的更改我得到一个异常:

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:

基础提供失败的提交。

堆栈跟踪是:

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

我的code是pretty的简单:

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());
    }
}

的code该片段是在为MyService ,它与一批5000追随者和它变得上述异常。然而,当我拉code相同的片段伸到的功能,只是手动添加几个随从,那么它不再抛出异常和追随者成功添加到我的数据库。 显然,数据库文件被锁定,什么可能会造成这个问题?

This snippet of code is inside MyService, it comes in with a batch of 5,000 followers and it's getting the above exception. 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. Apparently the database file is locked, what may be causing this issue?

推荐答案

我刚刚找到了在另一SO问题的答案:<一href="http://stackoverflow.com/questions/4348860/the-database-file-is-locked-with-system-data-sqlite">'The数据库文件与System.Data.SQLite

I just found out the answer in another SO question: 'The database file is locked' with System.Data.SQLite

讽刺的是,OP回答了自己的问题太多:)

Ironically, the OP answers his own question too :).

这篇关于实体框架使用SQLite异常:基础提供失败的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆