无法找到所请求的 .Net Framework 数据提供程序 - SQLite

21

我原本以为 SQLite 很简单,但是它却让我头疼不已。我只想创建一个应用程序,使用 ado.net 实体数据类连接到 SQLite 数据库。

我在测试该应用程序时,在运行 Windows XP 的虚拟计算机上出现了问题。当我部署到当前计算机和笔记本电脑上时,应用程序可以正常工作。

以下是在虚拟计算机上发生的情况:

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

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

enter image description here

enter image description here

我知道有很多帖子都谈论了这个问题,大多数都说你需要下载SQLite 的 .NET 提供程序。

我已经安装了 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>

我将SQLite连接字符串添加到了我的app.config文件中。

问题是现在我无法选择数据或向数据库插入记录。 当我尝试插入新记录时,我得到的异常是:

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

输入图像描述

2个回答

33

不得不添加:

 <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所在的输出目录


0
  1. 通过扩展安装SQLite工具箱

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

安装正确的x86版本,MSI中有一个选项可以安装VS设计器组件,在正确的安装下面有粗体文字详细说明。

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

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

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

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

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

现在您可以将SQLite作为绑定源连接,并直接通过“SQLite Database”选择您的数据库文件,而不是使用“SQLite Provider(由ErikEJ提供的EF6简易版)”。

请参考此链接,该解决方案取自详细的GitHub帖子,一步一步操作


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接