This documentation is archived and is not being maintained.

Connecting to Data

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

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


The Northwind data service in this example is read-only. You can view but not update the data.

To attach to a data source

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

  2. On the menu bar, choose Project, Add Data Source.

    The Attach Data Source wizard opens.

  3. In the Attach Data Source wizard, choose OData Service, and then choose Next.

  4. On the Enter Connection Information page, in the OData Source Address box, enter

  5. Under Login Information, choose the Windows Authentication option button, and then choose the Next button.

  6. On the Choose your Entities page, expand the Entities node.

  7. Choose the Customers, Order_Details, and Orders tables, and then choose the Finish button.

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

In this procedure, you established a connection to the Northwind sample database, which was exposed through an Open Data Protocol (OData) service. For your own applications, you must know the name of the database or service that you want to access and the address of the server where it’s hosted.

You also need permission to access and modify the database. Permissions are usually based on either Windows credentials (your Windows logon ID) or custom credentials that the database administrator assigns.

In the Attach Data Source wizard, you could have chosen Database, SharePoint, or WCF RIA Service as a data source. For a LightSwitch application, you can use data from a database such as SQL Server, from a SharePoint list, or from a Windows Communication Foundation Rich Internet Application (WCF RIA) service that’s designed for LightSwitch and hosted on a web server.

In the Warnings dialog box that appeared when you chose the Finish button, the messages warned of relationships that couldn’t be imported in addition to related entities that would be added. Based on the structure of the data source, LightSwitch helps make the best choices for your application. You will learn more about relationships in a later lesson.

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

Next lesson: Customizing Entity Fields