wpf SQL Server CE 不兼容的数据库版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16543400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:47:34  来源:igfitidea点击:

SQL Server CE Incompatible Database Version

c#wpflinq-to-sqlsql-server-ce

提问by Gaz83

I have a SQL Server CE 4.0 database (.sdffile) and when I trying doing a query on the database from my application (WPF) I get the following error.

我有一个 SQL Server CE 4.0 数据库(.sdf文件),当我尝试从我的应用程序 (WPF) 对数据库进行查询时,出现以下错误。

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\ShortageReport\MRPDatabase.sdf]

不兼容的数据库版本。如果这是兼容的文件,请运行修复。对于其他情况,请参阅文档。[数据库版本 = 4000000,请求版本 = 3505053,文件名 = \?\C:\Database\ShortageReport\MRPDatabase.sdf]

  • I have checked SQL Server CE 4 sp1 is installed.
  • I have tried creating the database in both Database.Net 4 and in the connection setup in vs2012.
  • I'm running windows 7 64bit
  • My connection string is stored in the app.config.
  • 我检查了 SQL Server CE 4 sp1 是否已安装。
  • 我尝试在 Database.Net 4 和 vs2012 的连接设置中创建数据库。
  • 我正在运行 Windows 7 64 位
  • 我的连接字符串存储在app.config.

I am using SQL Server Compact Toolbox to generate the context and the mappings.

我正在使用 SQL Server Compact Toolbox 生成上下文和映射。

My app.config:

我的app.config

<connectionStrings>
    <add name="DatabaseContext" 
         providerName="System.Data.SqlServerCe.4.0" 
         connectionString="Data Source=C:\Database\ShortageReport\MRPDatabase.sdf"/>
</connectionStrings>

Any ideas?

有任何想法吗?

回答by ErikEJ

Add a reference to the version 4.0 System.Data.SqlServerCe.dll ADO.NET provider

添加对版本 4.0 System.Data.SqlServerCe.dll ADO.NET 提供程序的引用

Then initialize the DataContextclass with a SqlCeConnection(4.0) object.

然后DataContextSqlCeConnection(4.0)对象初始化类。

using (SqlCeConnection conn = new SqlCeConnection(@"Data Source=C:\projects\Chinook\Chinook40.sdf"))
{
    using (Chinook db = new Chinook(conn))
    {
        var list = db.Album.ToList();
        if (list.Count > 0)
            System.Diagnostics.Debug.Print("It works!");
    }
}

回答by Saboor Awan

I updated SqlServerCe.dll reference from following path, and it fixed

我从以下路径更新了 SqlServerCe.dll 引用,它修复了

Reference Path:

参考路径:

C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll

回答by Jordi Espada

I've found on similar problem and uninstalling all frameworks SQL Server Compact 3.5 and SQL Server Compact 3.5 SP1 I've solved this issue.

我发现了类似的问题,卸载所有框架 SQL Server Compact 3.5 和 SQL Server Compact 3.5 SP1 我已经解决了这个问题。

Cheers,

干杯,