问题
I have a SQL Server CE 4.0 database (.sdf
file) and when I trying doing a query on the database from my application (WPF) I get the following error.
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]
- 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
.
I am using SQL Server Compact Toolbox to generate the context and the mappings.
My app.config
:
<connectionStrings>
<add name="DatabaseContext"
providerName="System.Data.SqlServerCe.4.0"
connectionString="Data Source=C:\Database\ShortageReport\MRPDatabase.sdf"/>
</connectionStrings>
Any ideas?
回答1:
Add a reference to the version 4.0 System.Data.SqlServerCe.dll ADO.NET provider
Then initialize the DataContext
class with a SqlCeConnection
(4.0) object.
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!");
}
}
回答2:
I updated SqlServerCe.dll reference from following path, and it fixed
Reference Path:
C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll
回答3:
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.
Cheers,
来源:https://stackoverflow.com/questions/16543400/sql-server-ce-incompatible-database-version