wpf C# 找不到数据提供程序。NET 框架请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16615845/
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-09-13 08:49:13  来源:igfitidea点击:

C# Could not find the data provider. NET Framework requested

c#wpfvisual-studio-2010mvvmsystem.data.sqlite

提问by wpf c

Im using Visual Studio 2010 Ultimate, C# WPF, MVVM, Sqlite.

我使用 Visual Studio 2010 Ultimate、C# WPF、MVVM、Sqlite。

I have this project that is running without problems (On Windows 8 x64, .NET Framework 4 Client Proile), but I get all this exceptions when run an installed application (On Windows 7 x32, .NET Framework 4 Client Proile):

我有一个运行没有问题的项目(在 Windows 8 x64、.NET Framework 4 Client Proile 上),但是在运行已安装的应用程序时我得到了所有这些异常(在 Windows 7 x32、.NET Framework 4 Client Proile):

Exception: System.Windows.Markup.XamlParseException: 'The invocation of the constructor of type' GestorDocument.UI.DeterminanteView 'that matches the specified binding constraints threw an exception.' (Line number: '3 ', line position '9'). ---> System.ArgumentException: The specified store provider can not be found in the configuration or is not valid. ---> System.ArgumentException: Could not find the data provider. NET Framework requested. It may not be installed.
??

This is my connection string:

这是我的连接字符串:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="GestorDocumentEntities" connectionString="metadata=res://*/GestorDocument.csdl|res://*/GestorDocument.ssdl|res://*/GestorDocument.msl;provider=System.Data.SQLite;provider connection string=&quot;data source=C:\SQLITE\BD\GestorDocument.s3db&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>  
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>

Please, Any idea?

请问,有什么想法吗?



Now it works! MY SOLUTION WAS:

现在它起作用了!我的解决方案是:

App.config in your project:

项目中的 App.config:

    <configuration>  

  <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, Version=1.0.85.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>


      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
      </startup>
    </configuration>

Include a reference of: (version for the machine on which the application will be installed.)

包括参考:(将安装应用程序的机器的版本。)

  • SQLite.Designer.dll
  • System.Data.SQLite.dll
  • System.Data.SQLite.Linq.dll
  • SQLite.Designer.dll
  • 系统数据.SQLite.dll
  • System.Data.SQLite.Linq.dll

Set "Copy local" property to True.

将“复制本地”属性设置为 True。

Add in machine.config this line between system.data and DbProviderFactories

在 machine.config 中添加 system.data 和 DbProviderFactories 之间的这一行

<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.85.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />

Ensure that the version of. NET Framework, which was developed the application, is installed on the test machine.

确保版本。NET Framework,它是开发应用程序,安装在测试机器上。

回答by

The System.Data.SQLiteprovider isn't installed on the machine. The correct installation not only drops the binaries on the machine (probably the GAC), but also drops an entry into machine.config that looks something like this (this is NOT REAL):

System.Data.SQLite供应商是不是安装在机器上。正确的安装不仅会删除机器上的二进制文件(可能是 GAC),还会删除 machine.config 中的一个条目,看起来像这样(这不是真实的):

<system.data>
  <DbProviderFactories>
    <add name="System.Data.SQLite"
         invariant="System.Data.SQLite"
         description="SQLite Framework Data Provider for SQLite databases lol"
         type="SomeProviderFactory, System.Data.SQLite, Etcetera=etcetera"/>
    <!--snip-->
  </DbProviderFactories>
</system.data>

Configuration settings (like this database provider configuration) in machine.configare inherited by your application's derp.exe.configfile. In your .config file, you are configuring EF to use the SQLite provider (from the middle of your EF connection string):

machine.config中的配置设置(如此数据库提供程序配置)由您的应用程序derp.exe.config文件继承。在您的 .config 文件中,您将 EF 配置为使用 SQLite 提供程序(从 EF 连接字符串的中间):

provider=System.Data.SQLite;

If you look up at the hypothetical entry, it has a provider name that's the same as in your connection string. That's how EF knows to use the SQLite factory to create a connection to the database. See, it's not really magic at all. Its just hidden.

如果您查看假设条目,它的提供程序名称与您的连接字符串中的名称相同。这就是 EF 知道使用 SQLite 工厂来创建到数据库的连接的方式。看,这根本就不是魔术。它只是隐藏。

So what's the solution? Hell if I know. I mean, I use a REAL compact database, not this SQLite stuff. You will either have to install SQLite on the target machine, add the factory definition to your .config file, or do something else, like construct a plane out of bamboo.

那么有什么解决办法呢?如果我知道,那该死。我的意思是,我使用的是一个真正的紧凑型数据库,而不是这个 SQLite 的东西。您要么必须在目标机器上安装 SQLite,将工厂定义添加到您的 .config 文件中,要么做其他事情,比如用竹子建造一架飞机。