实体Framewok代码首先“找不到ADO.NET提供者”与本地SQL Server CE DLL [英] Entity Framewok Code First "ADO.NET provider not found" with local SQL Server CE DLL's
问题描述
ArgumentException
:
具有不变名称System.Data.SqlServerCe.4.0的ADO.NET提供程序未在计算机或应用程序配置文件中注册,或无法加载。
内部异常消息说:
无法找到请求的.Net框架数据提供程序。可能没有安装。
我搜索过Google和SO,大部分评论表示确保App.config文件正确无误。我相信我的是(默认连接工厂和提供商部分),但这里是内容:
<?xml version = 1.0encoding =utf-8?>
< configuration>
< configSections>
< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> ;
< / configSections>
< startup>
< supportedRuntime version =v4.0sku =。NETFramework,Version = v4.0/>
< / startup>
< entityFramework>
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.SqlCeConnectionFactory,EntityFramework>
< parameters>
< parameter value =System.Data.SqlServerCe.4.0/>
< / parameters>
< / defaultConnectionFactory>
< providers>
< provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< provider invariantName =System.Data.SqlServerCe.4.0type =System.Data.Entity.SqlServerCompact.SqlCeProviderServices,EntityFramework.SqlServerCompact/>
< / providers>
< / entityFramework>
< / configuration>
当然,构建文件夹包含以下文件(除了特定于应用程序的文件):
- EntityFramework.dll
- EntityFramework.xml
- EntityFramework.SqlServer.dll
- EntityFramework.SqlServer.xml
- EntityFramework.SqlServerCompact.dll
- EntityFramework。 SqlServerCompact.xml
在每个amd64和x86子文件夹中都有以下文件:
- sqlceca40.dll
- sqlcecompact40.dll
- sqlceer40EN.dll
- sqlceme40.dll
- sqlceqp40.dll
- sqlcese40.dll
我确定该程序在开发机器上运行,因为已安装SQL Server CE,但是如何使用其他机器上的本地SQL Server CE dll来运行程序?
请参阅 http://tech.aendeavors.com/2011/06/09/bin -deploy-sqlce-4-0-and-ef-4-1 /
似乎可能丢失的相关位是:
-
确保System.Data.SqlServerCe被引用,并在属性中设置为复制
本地。 -
将以下内容添加到app.config中:
< system.data>
< DbProviderFactories>
< remove invariant =System.Data.SqlServerCe.4.0/>
< add name =Microsoft SQL Server Compact Data Provider 4.0
invariant =System.Data.SqlServerCe.4.0
description =.NET Framework Data Provider for Microsoft SQL Server Compact
type =System.Data.SqlServerCe.SqlCeProviderFactory,System.Data.SqlServerCe,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91/>
< / DbProviderFactories>
< /system.data>
I am writing a C# application which uses SQL Server CE 4.0 files, which are accessed through the Entity Framework 6.0 via code-first. (The application needs to be able to use local dll's for the SQL Server CE connection i.e. the application needs to be XCOPY deployable). The application runs fine on my development machine, but on other machines (e.g. VMs with just Win7 and .NET 4.0), I get an ArgumentException
:
The ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
The inner exception message says:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
I have searched Google and SO and most of the comments indicate ensuring the App.config file is correct. I believe mine is (default connection factory and provider sections), but here are the contents:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
</configuration>
The build folder includes the following files (in addition to the application-specific files, of course):
- EntityFramework.dll
- EntityFramework.xml
- EntityFramework.SqlServer.dll
- EntityFramework.SqlServer.xml
- EntityFramework.SqlServerCompact.dll
- EntityFramework.SqlServerCompact.xml
In each of the amd64 and x86 subfolders are the following files:
- sqlceca40.dll
- sqlcecompact40.dll
- sqlceer40EN.dll
- sqlceme40.dll
- sqlceqp40.dll
- sqlcese40.dll
I am certain the program runs on the development machine because SQL Server CE has been installed, but how do I get it to run using just local SQL Server CE dll's on other machines?
See http://tech.aendeavors.com/2011/06/09/bin-deploy-sqlce-4-0-and-ef-4-1/
It seems the relevant bits you might be missing are:
Make sure System.Data.SqlServerCe is referenced and set to "Copy local" in properties.
Add the following to app.config:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0"
invariant="System.Data.SqlServerCe.4.0"
description=".NET Framework Data Provider for Microsoft SQL Server Compact"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
这篇关于实体Framewok代码首先“找不到ADO.NET提供者”与本地SQL Server CE DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!