【问题标题】:SQlite Entity Framework ADO.net provider error 1.0.92.0SQlite 实体框架 ADO.net 提供程序错误 1.0.92.0
【发布时间】:2015-03-21 05:03:47
【问题描述】:

我试图了解 SQlite 和实体框架如何交互。 我在我的 Visual Studio 2013 中创建了一个新的控制台项目。我安装了 SQlite 1.0.92 的 nuget 数据包。 我创建了一个新的空模型 (edmx) 并尝试从静态示例数据库(例如 northwind.db)中填充它。 在此之后我收到此错误:错误 0175:名为“System.Data.SQLite.EF6”的 ado.net 提供程序未在计算机上注册。

有什么想法吗?

谢谢 洛伦佐

【问题讨论】:

  • 您使用的是什么版本的 Visual Studio?你的配置文件是什么样子的?
  • VS2013。配置文件是使用 nuget 安装组件后创建的文件
  • 我得到“无法为您的数据连接找到与此版本兼容的实体框架数据库提供程序”,有什么想法吗?完整描述见social.msdn.microsoft.com/Forums/en-US/…

标签: entity-framework sqlite


【解决方案1】:

经过一些测试,我找到了可能的解决方案。让我们从头开始:

从 sqlite 服务器(x86 版本)下载 SQLite ado.net 提供程序。 您必须在 GAC 中手动注册这三个库:system.data.sqlite、system.data.sqlite.ef6、system.data.sqlite.designer 和 gacutil

启动 Visual Studio 2013。添加对 nuget sqlite 1.0.92.0 的引用(这也将添加对实体框架 6.1 的引用)。

您的 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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <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" />
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".Net Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
    </DbProviderFactories>
  </system.data>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

    </providers>
  </entityFramework>
<connectionStrings>

在服务器资源管理器中添加到数据库的新 Sqlite 连接并进行测试。 现在向您的项目添加并创建一个新的空 ado.net 实体模型。

这应该可以工作...但是当您运行应用程序并在其中一个 dbset 中获取一些记录时,您将收到一个异常,告诉您没有为您的连接注册 ado.net 提供程序 (system.data.sqlite) .

转到您的配置文件并将其添加到您的提供程序部分(只需复制前面的 sqlite 行并剪切不变名称中的 .ef6 后缀):

<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

保存所有并重建应用程序。现在它可以工作了,但是如果您返回模型详细信息并尝试从数据库中刷新模型,您将再次获得提供程序异常。注释最后添加的提供程序并重试。它的工作原理!!!

我认为这是由于 syste.data.sqlite 和 system.data.sqlite.ef6 中的提供程序名称之间存在冲突

尽管如此,我不能先做模型(投影一个模型,然后从中创建一个新数据库),因为我遇到了另一个 ado.net 提供程序异常。

对此有什么想法吗?

谢谢 洛伦佐

_________________ 04-2014 年更新 _________________

经过一些测试和谷歌搜索... 我读到,当你想使用 VS 设计工具时,你必须安装正确的 x86 版本的 SQLite 驱动程序。这些驱动程序要与 VS 工具正常工作,需要在安装过程中在 GAC 中注册其 System.Data.SQLite 版本(只有在此 VS 知道在哪里可以找到设计工具的连接提供程序之后)。 当您使用模型优先的方法并要求模型创建数据库而不是使用在 app.config 中注册的正确驱动程序时,它会尝试打开与在 GAC 中注册并由可视模型创建工具使用的实体连接(并且不兼容)。我认为目前没有办法将 VS 的实体建模工具与 SQLite 提供程序一起使用。

洛伦佐

【讨论】:

  • 您不再需要在 GAC 中手动注册 SQLite ADO.Net 提供程序。有一个原生支持 VS2013 的构建。转到system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki 并搜索“Visual Studio 2013”​​。截至今天,安装名为 sqlite-netFx451-setup-bundle-x86-2013-1.0.92.0.exe。
  • 此修复适用于我在 vs2010 上通过 nuget 安装的 sqlite 1.0.92.0。谢谢。
  • 不幸的是,此时即使使用 1.0.92.0 版,即使使用 SQLite.org 的 VS2013 x86 安装程序,Model First 也无法与 Visual Studio 2013 和 EF6 一起使用。 :(
  • 不明白,为 VS2013 安装/卸载 1.0.94.0 x86 4.5.1 几次,但对我没有任何效果。无法为 SQLite 创建新的数据连接。
【解决方案2】:

@LoxLox :我认为您不必向 GAC 注册 dll。我有和你一样的问题,但我只需要编辑 .config 文件,如post 中讨论的那样,通过将 .EF6 后缀添加到不变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多