---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/