Reputation: 1661
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):
In each of the amd64 and x86 subfolders are the following files:
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?
Upvotes: 10
Views: 24968
Reputation: 863
In my case, "EntityFramework.SqlServerCompact" package was missing. Just wanted to share if in case it can save someone's day!
Upvotes: 1
Reputation: 83
Sorry about the late response - actually, there's a really simple solution:
If you investigate the packages\EntityFramework.6.1.3\lib\net45 folder, you'll notice that there's another dll that's already in there - EntityFramework.SqlServer.
Simply add a reference to that, and everything will work.
Upvotes: 2
Reputation: 2342
I had the same issue and nothing worked for me. The only thing that resolved my this issue for me was to uninstall SQL Server Compact from my machine (via add/remove programs) and re-install it.
Upvotes: 0
Reputation: 2950
I was facing the same problem today.
After reinstalling EF several times, what solved my problem was referencing EF in my Console project along with the DAL project (the one that actually uses EF).
If you're using a reference that in turn references EF, you gotta add it to this project as well.
Upvotes: 5
Reputation: 19267
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>
Upvotes: 23