[英]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.