Reputation: 87
I'm developing a WPF application using Entity Framework 4 and SQL Server CE database 3.5 and it's correctly working.
However I'd like to have this application to run on a machine with .Net Framework 4 installed but without the SQL Server Compact 3.5
drivers. And no installer. Is it possible?
I have tried the following:
create a section in the app.config
<configuration>
<connectionStrings>
<add name="DbEntities"
connectionString="metadata=res://*/Model.Model1.csdl|res://*/Model.Model1.ssdl|res://*/Model.Model1.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=|DataDirectory|\Data\Database1.sdf""
providerName="System.Data.EntityClient"/>
</connectionStrings>
<system.data>
<DbProviderFactories>
<add name="SQL Server Compact Edition Data Provider"
invariant="System.Data.SqlServerCe"
description=".NET Framework Data Provider for Microsoft SQL Server Compact Edition"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
</configuration>
add references to System.Data.SqlServerCe
and System.Data.SqlServerCe.Entity
and allow local copy
build the application and copy it on a machine without SQL Server CE drivers installed. When it comes to create the data context I keep getting this error :
System.ArgumentException: The specified store provider cannot be found in the configuration, or is not valid. --->
System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
Am I losing time? Or should I just switch to SQLite?
Thanks!
EDIT:
Thanks to josemiguel.torres' answer, I check at this post detailling how to achieve this. However, I still have an assembly error.
"System.IO.FileLoadException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.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)"
So I had a look at this other post explaining how to fix this issue. After adding some assembly binding:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
<bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
It still doesn't work ... :| Error message is similar :
System.IO.FileLoadException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.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)
File name: 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
I'm out of solution. Anyone?
EDIT 2:
1.I have uninstalled all the Microsoft "SQL Server Compact Edition" versions from my machine.
2.I checked the machine.config version : there is no entries in the DbProviderFactories section.
3.I downloaded the 3.5 SP2 drivers from there and installed the x86 package.
4.I check my machine.config (v4 x86) and the following entries has been created under the DbProviderFactories node:
<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
Why is it 3.5.0.0 and not 3.5.1.50???
juste in case: my dev machine is on Win7 x64 and target machine is WinXP x86.
Upvotes: 2
Views: 4282
Reputation: 87
I gave up with SQL CE 3.5 and switched to 4.0. It's working fine, thanks to this article. Thanks Erik ;)
Upvotes: 0
Reputation: 41819
Install 3.5 SP2, and modify the app.config as follows:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ChinookEntities" connectionString="metadata=res://*/Chinook.csdl|res://*/Chinook.ssdl|res://*/Chinook.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=C:\Users\erik.COMMENTOR\Documents\Visual Studio 2010\Projects\SqlCeTest\Chinook.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.3.5" />
<add name="Microsoft SQL Server Compact Data Provider 3.5" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.50, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly xmlns="">
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Make sure to use the System.Data.SqlServerCe.dll and System.Data.SqlServerCe.Entity.dll from the C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Private folder
Upvotes: 2