问题
I need to update my SqlCE3.5 database to 4.0.
I get the following error message when I'm trying to access my 3.5 sdf/database using the new CE4.0 connection provide :-
System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlServerCe.SqlCeInvalidDatabaseFormatException: The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method.
Anyone know how I can do this? Obviously I need to do it programatcially but i'm not sure what I should do / what references I need to add, etc.
Cheers!
回答1:
Call System.Data.SqlServerCe.SqlCeEngine.Upgrade
. See MSDN, which contains sample code.
回答2:
You needn't upgrade when you see this error:
The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method.
Simply:
- Right-click your Project in Solution Explorer
- Choose properties, go to References tab
- You'll see a reference called:
System. Data.SqlServerCe Type/net version/4.0
- delete this item (select item and then click remove in the bottom of this window). - Click on the "add..." button left of the "remove" button
- In the .NET tab, find
System.Data.SqlServerCe 3.5
and add this. - Compile your project!
I think this will work.
来源:https://stackoverflow.com/questions/4744527/how-can-i-upgrade-my-sql-server-ce-3-5-sdf-database-to-sql-server-ce-4-0