entity-framework - Sqlite .NET 和 Entity Framework - "attempt to write a readonly database"

标签 entity-framework sqlite

---edit--- 我可以提供任何其他信息来帮助解决这个问题吗?

我正在尝试在 .NET WCF Web 服务中启动并运行 Sqlite 和 Entity Framework 。

当我尝试将任何内容保存到数据库时,我收到错误“尝试写入只读数据库”。以下是完整的错误信息:

System.Data.EntityException: An error occurred while starting a transaction on the provider connection. See the inner exception for details.

---> System.Data.SQLite.SQLiteException: Attempt to write a read-only database

Attempt to write a readonly database
at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
at [snip]........................................................> at System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel) at System.Data.Common.DbConnection.BeginTransaction() at System.Data.EntityClient.EntityConnection.BeginTransaction() at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave) at System.Data.Objects.ObjectContext.SaveChanges() at ...

这是我在 Web.config 中的 EF 配置(带有换行符以便于阅读):

<connectionStrings>
   <add 
      name="FooEntities" 
      connectionString="metadata=res://*/FooDataModel.csdl|
      res://*/FooDataModel.ssdl|
      res://*/FooDataModel.msl;
      provider=System.Data.SQLite;
      provider connection string='data source=C:\domains\myfoosite.com\wwwroot\FooService\Foo.sqlite'"
      providerName="System.Data.EntityClient" />
<connectionStrings>

为什么我会收到此错误?为什么数据库是只读的?

我尝试过的一些事情:

  • 确保目录和文件是 可由 Web 服务写入。 (我有 尝试将纯文本文件写入 与测试相同的目录。)

  • 我已将“read only=False”添加到 连接字符串。

最佳答案

原来问题出在 IIS 安全设置上。我必须打开脚本写入权限,它神奇地开始工作了。

关于entity-framework - Sqlite .NET 和 Entity Framework - "attempt to write a readonly database",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3130182/

相关文章:

wcf - 在基于 WCF 的企业应用程序中使用 Entity Framework 的哪个变体

entity-framework - DbSet.Remove 和 DbContext.Entry(entity).State = EntityState.Deleted 之间的区别

python - 如何将多个列表插入到sqlite列中

python - 使用 SQLite 了解 PonyORM 中的内存消耗

java - SQLite 异常 : table already exists

c# - SQLite "automatic index on MyTable(Id)"当字段是表的主键时

.net - 获取一次数据库命中中的总记录数和自定义记录数

asp.net - 自定义 OWIN/Katana UserManager 工厂行为

c# - 我应该如何使用集合?

python - 使用 CSV 文件加速 SQLite3 UPDATE 功能