我遇到了这个问题。从我的程序到DataGrid和DataSet可以看到SQLite数据库。问题出现在依赖于EntitiyFramework 5.0的查询的第一个引用中。在这种情况下,数据库不可用,并返回以下错误:
System.Data.EntityCommandExecutionException:发生错误 执行命令定义。查看内部异常 细节。 ---> System.Data.SQLite.SQLiteException:SQL逻辑错误或 缺少数据库
我的app.config有以下
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="dbConnectionString" connectionString="data source=db.sqlite" providerName="System.Data.SQLite" />
<add name="MyApp.My.MySettings.dbConnectionString" connectionString=""data source=db.sqlite" providerName="System.Data.SQLite"" />
<add name="dbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string="data source=db.sqlite"" providerName="System.Data.EntityClient" /></connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
如何设置数据库以便EF始终可用?
答案 0 :(得分:0)
System.Data.Sqlite不支持为实体框架创建数据库。您需要将SQLite数据库添加到项目