C# 与Sql不兼容的数据库版本

C# 与Sql不兼容的数据库版本,c#,linq-to-sql,sql-server-ce,sqlmetal,C#,Linq To Sql,Sql Server Ce,Sqlmetal,我在Visual Studio中创建了一个扩展名为.sdf的本地数据库文件(Sql Server Compact数据库文件),并使用SqlMetal.exe将Linq连接到我的Sql数据库文件。然而,它给了我一个错误,说不兼容的数据库版本 Incompatible Database Version. If this was a compatible file, run repair. For other cases refer to documentation. [ Db version = 4

我在Visual Studio中创建了一个扩展名为.sdf的本地数据库文件(Sql Server Compact数据库文件),并使用SqlMetal.exe将Linq连接到我的Sql数据库文件。然而,它给了我一个错误,说不兼容的数据库版本

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 ]

假设我安装了Microsoft SQl Compact Server,包括32位和64位版本,并且运行在64位Windows 8上。有人知道怎么修吗?谢谢

您必须使用SqlCeConnection对象初始化DataContext才能正常工作,不要使用连接字符串

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

using (var context = new MyDataContext(conn))
{}

根据错误消息,它需要一个CE3.5数据库,但您的数据库是4.0。我对VisualStudio使用/包含的各种版本了解不够,无法告诉您如何解决这个问题,但一个简单的方法是使用Server Compact 3.5来创建数据库。我将如何做到这一点?谢谢你刚才的答复