Export (0) Print
Expand All

How to: Use SQL Server 2005 Compact Edition 3.1 in Managed Projects (Devices)

Visual Studio 2008

This topic explains how to use SQL Server 2005 Compact Edition 3.1 in managed smart device projects. Developers sometimes use this version of SQL Server because it is built into the ROM of Windows Mobile 6 devices and emulators.

Important noteImportant Note:

You must complete Walkthrough: Creating Windows Forms Applications for a Device, before you begin.

To add a reference to a managed data provider

  1. Download and install the Microsoft SQL Server 2005 Compact Edition Developer Software Development Kit.

  2. Open the device project that you created by completing Walkthrough: Creating Windows Forms Applications for a Device.

  3. In Solution Explorer, right-click the project and then click Add Reference.

    The Add Reference dialog box appears.

  4. Click the Browse tab, find the file drive:\Program Files\Microsoft SQL Server Compact Edition\v3.1\SDK\bin\platform\System.Data.SqlServerCe.dll, and then click OK.

  5. (Visual Basic only) Add a reference to System.Data.

To add a SQL Server 2005 Compact Edition 3.1 database to the project

  1. In Solution Explorer, right-click the project, point to Add, and then click Existing Item.

    The Add Existing Item dialog box appears.

  2. In the Object of type drop-down, select All Files (*.*).

  3. Find the file drive:\Program Files\Microsoft SQL Server Compact Edition\v3.1\SDK\Samples\Northwind.sdf and then click Add.

  4. Click Cancel in the Upgrade to SQL Server Compact 3.5 Database and Data Source Configuration Wizard dialog boxes.

    The database file appears in Solution Explorer.

To connect to the database

  1. From the Toolbox, drag a Button control onto the form.

    If you cannot see the Toolbox in the integrated development environment (IDE), click Toolbox on the View menu. If you cannot see the Device Controls tab in the Toolbox, right-click the Toolbox, and then click Show All.

  2. Right-click the Button on the form, and then click Properties.

  3. In the Properties window, type Connect, and press ENTER to set the Text property.

  4. Double-click the Button on the form.

    The Code Editor opens with the cursor positioned in the event handler.

  5. Insert the following Visual Basic code:

    Dim conn As New System.Data.SqlServerCe.SqlCeConnection("data source='\Program Files\DeviceSample\Northwind.sdf';")
    conn.Open()
    

    —or—

    Insert the following C# code:

    System.Data.SqlServerCe.SqlCeConnection conn = new System.Data.SqlServerCe.SqlCeConnection("data source='\\Program Files\\DeviceSample\\Northwind.sdf';");
    conn.Open();
    
    NoteNote:

    You may need to modify the connection string, depending on the deployment folder of the project.

    When you debug or deploy this application, Visual Studio copies the Northwind.sdf sample database and deploys the application to the device. The application connects to the database but does not perform any operations.

Community Additions

ADD
Show:
© 2015 Microsoft