Having some issues deploying applications with ASP.NET MVC 3 and Entity Framework Code First using Microsoft SQL Server Compact Edition, even after I have installed on the server Microsoft SQL Server Compact Edition and Express.
Deploying ASP.NET MVC 3 with Entity Framework Code First you may have a few issues when deploying into a computer with only .NET 4 installed, I have to install MVC 3 dlls and Entity Framework CF to use the Compact Database.
This is the error you may get if you do not copy all the dlls.
[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +160
System.Data.Entity.Infrastructure.SqlCeConnectionFactory.CreateConnection(String nameOrConnectionString) +168
System.Data.Entity.Internal.LazyInternalConnection.Initialize() +158
System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel() +10
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +265
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +17
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +62
System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TRes
Steps to fix the problem
You need System.Data.SqlServerCe.dll make sure in the properties you enable the local copy.
Add the provider to your web.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>
Then you going to get this error, yet not to worry.
Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8482. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.
Now you should reference the dll System.Data.SqlServerCe.Entity.dll located in a private directory
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Private
Make sure you set the flag in the properties to copy it local, so gets deploy with all the dlls to the server that may not have that dll.
You may also get the error: Could not load file or assembly 'System.Data.SqlServerCe.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Still not having any success is running ASP.NET MVC 3 with Microsoft SQL Server Compact Edition
Cheers
Al