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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9725979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 08:35:38  来源:igfitidea点击:

Unable to find the requested .Net Framework Data Provider - SQLite

c#sqlitedeploymentado.net

提问by Tono Nam

I thought that sqlite was simple but it is giving me a hard time. I just want to create an application where I can connect to a sqlite database using the ado.net entity data classes.

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

I am having this problem when testing the application on a virtual computer running windows xp. the application works fine on my current computer and also on my laptop when I deploy them.

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

Here is what happens on the virtual computer :

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

  • The application is able to launch.
  • The application is able to interact with the database using System.Data.SQLite
  • The application is not able to connect to the database using The ADO.NET Entity data models
  • 该应用程序能够启动。
  • 应用程序能够使用 System.Data.SQLite 与数据库交互
  • 应用程序无法使用 ADO.NET 实体数据模型连接到数据库

when I try to connect I get the following exception:

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

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

I know there are a lot of post that talk about this and most of them say that you need to download the .NET provider for Sqlite.

我知道有很多帖子都在谈论这个,而且大多数帖子都说您需要下载Sqlite.NET 提供程序。

I have already installed the sqlite-netFx40-setup-bundle-x86-2010-1.0.79.0.exe and I get the same problem. What should I do?

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



Edit

编辑

I managed to establish a connection by adding:

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

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

to my app.config file.

到我的 app.config 文件。

The problem is that now I cannot select data nor insert records to the database. The exception that I get when I try to insert a new record now is:

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

A null was returned after calling the 'GetService' method on a store provider instance of type 'System.Data.SQLite.SQLiteFactory'. The store provider might not be functioning correctly.

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

enter image description here

在此处输入图片说明

采纳答案by Tono Nam

had to add:

必须补充:

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

to my app config file. and it now looks like:

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

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

In the location where sqlite was installed I had to copy

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

enter image description here

在此处输入图片说明

to my output directory where my program exe is located

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