【问题标题】:Unable to find the requested .Net Framework Data Provider - SQLite找不到请求的 .Net Framework 数据提供程序 - SQLite
【发布时间】:2012-04-01 07:55:01
【问题描述】:

我认为 sqlite 很简单,但它让我很难过。我只想创建一个可以使用 ado.net 实体数据类连接到 sqlite 数据库的应用程序。

我在运行 windows xp 的虚拟计算机上测试应用程序时遇到了这个问题。该应用程序在我当前的计算机上运行良好,并且在我部署它们时也可以在我的笔记本电脑上运行。

这是虚拟计算机上发生的情况:

  • 应用程序能够启动。
  • 应用程序能够使用 System.Data.SQLite 与数据库交互
  • 应用程序无法使用 ADO.NET 实体数据模型连接到数据库

当我尝试连接时,出现以下异常:

我知道有很多帖子都在讨论这个问题,其中大多数都说你需要下载.NET provider for Sqlite.

我已经安装了 sqlite-netFx40-setup-bundle-x86-2010-1.0.79.0.exe 并且遇到了同样的问题。我该怎么办?


编辑

我设法通过添加以下内容建立了连接:

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

到我的 app.config 文件。

问题是现在我无法选择数据也无法将记录插入数据库。我现在尝试插入新记录时遇到的异常是:

在“System.Data.SQLite.SQLiteFactory”类型的商店提供程序实例上调用“GetService”方法后返回 null。商店提供商可能无法正常运行。

【问题讨论】:

    标签: c# sqlite deployment ado.net


    【解决方案1】:

    必须补充:

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

    到我的应用程序配置文件。现在看起来像:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0.30319" sku=".NETFramework,Version=v4.0,Profile=Client" />
      </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>
    </configuration>
    

    在安装 sqlite 的位置我不得不复制

    到我的程序 exe 所在的输出目录

    【讨论】:

      【解决方案2】:
      1. 通过扩展安装 SQLite Toolbox

      2. 下载最新的安装文件 sqlite-netFx46-setup-bundle-x86-2015-1.0.xxx.0.exe

      安装正确的 x86 安装,安装 VS 设计器组件是 MSI 中的一个选项,正确安装下方有粗体文本详细说明。

      单击 SQLite 工具箱下方已连接数据库上方的蓝色问号,重新启动并检查 GAC 中的 SQLite 是否已正确安装。

      此时您应该会看到“GAC 中的 SQLite EF6 DbProvider - 是的。”

      否则,您过去很可能手动配置了 machine.config。删除您在 system.data > DbProviderFactories 下所做的更改。

      重新启动 VS,您应该会看到“GAC 中的 SQLite EF6 DbProvider - 是的。”

      1. 在 NuGet 管理器下安装 System.Data.SQLite

      您现在可以连接到 SQLite 作为绑定源,并通过“SQLite 数据库”与“SQLite 提供程序(ErikEJ 的 EF6 简单)”直接选择您的数据库文件。

      refer to this link, this solution was taken from a detailed github post, step by step

      【讨论】:

        猜你喜欢
        • 2012-06-06
        • 1970-01-01
        • 2013-02-18
        • 1970-01-01
        • 1970-01-01
        • 2011-09-24
        • 1970-01-01
        • 2013-07-05
        相关资源
        最近更新 更多