Creating a new SQL Server Compact database using Visual Studio

Posted: (EET/GMT+2)

 

If you are developing applications for, say, the desktop, you might occasionally need to create a new SQL Server Compact Edition database, i.e. the .SDF file to store you data into. Although there are many ways to do this, one easy way to do this is directly from Visual Studio 2008. Here’s how to do it.

First, go to Visual Studio's Server Explorer window. Right-click the Data Connections node, and choose Add Connection from the popup menu. The Add Connection dialog box now opens. Next, unless the selection is already correct, click the Change button next to the data source field. Another dialog box opens, titled Change Data Source.

From this dialog box, select the Microsoft SQL Server Compact 3.5 source (or whichever version you happen to have). Then click OK, and you will return to the previous Add Connection dialog box. The dialog box layout has changed slightly, and now contains a Create button in the Connection Properties section.

Click the Create button, specify the necessary options, and finally click OK to create your .SDF file, and then start adding tables and data to it. Easy!