Export (0) Print
Expand All

How to: Add a SQL Server Compact Edition Database to a Project 

This topic is new for Visual Studio 2005 SP1.

There are two ways to add a SQL Server Compact Edition database to a Visual Studio project. You can add an existing database to a project, or you can create a new database by using Visual Database Tools and then later include it in a project.

Creating a New SQL Server Compact Edition Database

You create new databases using the Add Connection dialog box accessible through Server Explorer.

To create a new SQL Server Compact Edition database

  1. To open Server Explorer, on the View menu, click Server Explorer.

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

  3. If the Add Connection dialog box opens, verify that the Data Source is the .NET Framework Data Provider for SQL Server Compact Edition. If it is not, click the Change button, click the Microsoft SQL Server Compact Edition data source, and click OK.

  4. Leave the default selection of My Computer in the Data Source area.

  5. Click the Create button in the Connection Properties area.

  6. In the Create New SQL Server Compact Edition Database dialog box, you can specify the file path, database file name, and password of the new database. You can also choose to encrypt the data. For more information about the choices in this dialog box, you can press F1 or click the Help button in the dialog box.

  7. Click OK to return to the Add Connection dialog box. Note that the Database box now contains the path to the new database.

  8. Click OK to create the data connection in Server Explorer.

    Now you can expand the connection and right-click the Tables node to start designing the schema that defines the database.

  9. To add this database to your project, follow the directions for adding existing databases below.

Adding an Existing Database to a Project

You can use the Add Existing Item dialog box to browse to an existing SQL Server Compact Edition database file (.sdf) and add it to a project. You need to have an existing project loaded into the integrated development environment (IDE). After you add the database to your project, the Data Source Configuration Wizard automatically opens. You can then select the database objects (only tables in the case of SQL Server Compact Edition) to add to the generated dataset that the wizard creates. After you complete the wizard, the tables are added to the Data Sources window, ready to be dropped onto forms to create data-bound controls.

To add an existing SQL Server Compact Edition database to a project

  1. On the Project menu, click Add Existing Item.

  2. In the Add Existing Item dialog box, browse to the location of the SQL Server Compact Edition database file (.sdf) you want to use in the project, and then click Add.

    After you add the database file, the Data Source Configuration Wizard opens to the Choose your Database Objects page, and you can select the tables to use in the application.

  3. Expand the Tables node and select the tables you want to use in your application.

  4. Click Finish and the database is added to the project along with a typed dataset that includes the tables selected in the previous step.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft