How to: Upgrade SQL Server Compact 3.0, 3.1 and 3.5 database files to SQL Server Compact 4.0

A database file that was created in an earlier version cannot be opened by SQL Server Compact. The database file must be upgraded to SQL Server Compact 4.0. After the file is upgraded, it can no longer be used by earlier versions. To open the database file from an earlier version of SQL Server Compact (version 3.1 or 3.0 or 3.5), use the Upgrade to SQL Server Compact Database dialog box, or use the SqlCeEngine.Upgrade application programming interface.

Note Note

The Upgrade dialog box is available in the Server Explorer of Visual Studio.

To use the Upgrade to SQL Server Compact 4.0 Database dialog box

  1. Open Server Explorer.

  2. Right-click Data Connections and click Add Connection.

  3. Click Microsoft SQL Server Compact 4.0.

  4. Check Always use this selection (optional). Click Continue.

  5. Click Browse and locate, or type the path for, the database file you want to upgrade.

  6. Enter a password in the Password text box, if applicable.

  7. If you click Test Connection to open a database file created by using an earlier version of SQL Server Compact, you receive the following message: The selected database was created with an earlier version of SQL Server Compact and needs to be upgraded to SQL Server Compact 4.0 before the connection can be opened or tested. Upgrade the database by creating a new data connection and completing the Add Connection dialog box. 

    Note Note

    The file name extension of SQL Server Compact is *.sdf, which is the same file name extension as that of earlier versions. However, after a database file is upgraded to SQL Server Compact, you will no longer be able to open the file by using the earlier versions of SQL Server Compact.

  8. The destination path for the upgraded SQL Server Compact database is populated with the source path from the Add Connection dialog box. The path cannot be changed. Your old database will be available as a backup (.bak) file in the same folder. Click OK and the Upgrade to SQL Server Compact Database will be displayed.

  9. Enter a password for the new database (optional).

  10. Click OK.