Connecting to Data
Collapse the table of content
Expand the table of content

Connecting to Data

In this lesson, you will learn how to connect to an external database to provide data for a LightSwitch application.

Note Note

In order to complete the LightSwitch guided tour, you must download and install the Northwind sample database. For more information, see Installing the Northwind Sample Database

Most business applications use a "forms over data" model. Forms, which are called screens in LightSwitch, display and update data that is stored in a database. You already know how to display and update data stored in the local LightSwitch database. In real world applications, you want to connect to existing data in an external database. The first step is to specify a connection to that database.

To attach to a data source

  1. In Solution Explorer, select the Data Sources node.

  2. On the Project menu, click Add Data Source.

    The Attach Data Source wizard opens.

  3. In the Attach Data Source wizard, click Database and then click Next.

    The Choose Data Source dialog box is displayed.

    Note Note

    If you have previously connected to a database in LightSwitch, this dialog box is not displayed and you can skip the next step.

  4. In the Choose Data Source dialog box, click Microsoft SQL Server and then click Continue.

    The Connection Properties dialog box is displayed.

  5. In the Connection Properties dialog box, enter the values in the following table, and then click OK.

    Field

    Value

    Server Name

    .\SQLExpress

    Log on to the server

    Use Windows Authentication

    Select or enter a database name

    Northwind

    The Choose your Database Objects wizard page is displayed.

  6. Expand the Tables node.

  7. Select the Customers, Order_Details , and Orders tables and then click Finish.

    The NorthwindData data source is added to the project and entities are created for Customers, Orders, and Order_Details.

In this procedure you established a connection to the Northwind sample SQL Server database. For your own applications, you have to know the name of the database that you want to access and the name and path of the server where it is hosted.

You also need permission to access and modify the database. Permissions are usually based on either Windows Authentication (your Windows logon ID) or SQL Server Authentication. SQL Server Authentication requires a user name and password that are assigned by the database administrator.

In the Attach Data Source wizard, you could have chosen SharePoint or WCF RIA Service as a data source. LightSwitch enables you to use data from a SharePoint List or from a Windows Communication Foundation Rich Internet Application (WCF RIA) service designed for LightSwitch and hosted on a Web server.

In the Connection Properties dialog box, Microsoft SQL Server is the only data source listed. Although only SQL Server is supported directly, third-party extensions let you connect to other types of databases.

In the next lesson, you will learn how to work with the data entities that you just created.

Next lesson: Customizing Entity Fields

Community Additions

ADD
Show:
© 2016 Microsoft