dinsdag 24 augustus 2010

Upgrading a Sql Server Compact database file

Recently I upgraded my project from Sql Server Compact 3.0x to Sql Server Compact 3.5 (I was already using VS 2008, but with SQL Server Compact 3.0x that comes with VS 2005). You can do this easily by changing the System.Data.SqlServerCe reference in your project to the new 3.5 dll.

But when you try to run the project using an existing Compact database, you get the following exception: 
"The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method."

image

You can indeed upgrade the file using the code as indicated in the exception message (SqlCeEngine.Upgrade()). But because I’m always deploying the application with a ‘ready-to-start’ sdf file, I only need to do the upgrade once. Therefore I decided to use Sql Server Management Studio 2008 to upgrade the file for me.

You can use following steps to upgrade:
1) Open Sql Server Management Studio 2008 and choose ‘Sql Server Compact Edition’
image 
2) Choose ‘Browse for more’ in the ‘database file’ combo box; an explorer window will open and you can browse to your sdf file.
3) Management Studio will detect that the file was created in a previous Sql Server Compact version and displays a warning message (which basically says the same as the .net exception):
image
4) When you press OK here, Management Studio converts the file for you. You can now run your program again, using the upgraded sdf file.

Geen opmerkingen:

Een reactie posten