1

I have a C# application compiled on net 4.5.

I need to create a SQL Server CE 3.5 database file because it will be used on a Windows CE 6 device.

When I create a database from code using

SqlCeEngine en = new SqlCeEngine(connectionString);
en.CreateDatabase();

it's version 4 and not compatible with net compact 3.5

How can I force the SQL Server CE version to 3.5 on net 4.5?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Massimo
  • 11
  • 2
  • You may try to specify a Version in your connection string. Possibly you have to use "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=myPath\myData.sdf;" see https://www.connectionstrings.com/sql-server-compact/ – josef Jan 29 '15 at 05:35
  • Do not use the OLEDB provider from .NET... – ErikEJ Jan 29 '15 at 16:40

2 Answers2

2

You need to reference version 3.5.1.0 of System.Data.SqlServerCe.dll from your project instead of version 4.0.0.0.

You can install the 3.5 SP2 desktop runtime from here: http://www.microsoft.com/en-us/download/details.aspx?id=5783

ErikEJ
  • 40,951
  • 5
  • 75
  • 115
  • @ErickEJ I'm having the same problem, I've installed the 3.5 version and want to make sure if I make the changes in my app.config from – VcDeveloper Sep 27 '17 at 05:26
  • Also, I just did a Nuget search and found EntityFramework.SqlServerCompact.Legacy, so I'm assuming rather than changing the app.config is to remove 4.0 version and install this one correct? – VcDeveloper Sep 27 '17 at 05:33
-2

My recommendation is to switch to SQLite instead. SQL Server Compact edition has been deprecated / discontinued. Even MS has started recommending using SQLite for embedded development in latyer environments: https://msdn.microsoft.com/en-us/library/ee486593.aspx

SQLite databases are compatible between the desktop / server side and the mobile side.

tcarvin
  • 10,715
  • 3
  • 31
  • 52