0

I created a local database file (Sql Server Compact database file) in Visual Studio with the extension .sdf and I was using SqlMetal.exe to connect Linq to my Sql database file. However it gives me an error, saying that Incompatible Database Version.

Incompatible Database Version. If this was a compatible file, run repair. For other cases refer to documentation. [ Db version = 4000000,Requested version = 3505053,File name = \\?\C:\Database\Contact\ContactDatabase.sdf ]

Consider that I have Microsoft SQl Compact Server installed, both 32 and 64 bit version and I'm running on Windows 8, 64 bit. Does anyone know how to fix it ? Thanks

Faris Zacina
  • 14,056
  • 7
  • 62
  • 75
Hoang Minh
  • 1,066
  • 2
  • 21
  • 40
  • Per the error message, it expects a CE 3.5 database, but your database is 4.0. I don't know enough about the various versions used/included with Visual Studio to tell you how to fix that, but one easy approach would be to use Server Compact 3.5 to create the database instead. – Jeroen Mostert Oct 17 '14 at 08:22

1 Answers1

1

You must initialize your DataContext with a SqlCeConnection object for this to work, do not use a connection string.

var connString = "Data Source=C:\data\mydb.sdf");
var conn = new SqlCeConnection(connString);

using (var context = new MyDataContext(conn))
{}
ErikEJ
  • 40,951
  • 5
  • 75
  • 115