Connecting to Data in a LightSwitch Application
For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.
In this lesson, you’ll learn how to connect to an external database to provide data for a LightSwitch application.
Connect to Data
Most business applications use a "forms over data" model. This means that 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, as shown in Step 2: Define the Data. In real-world applications, you’ll often want to connect to data in an external database. As your first step, you'll specify a connection to a sample database called Northwind, which is available through an Open Data Protocol (OData) service.
The Northwind database in this example is read-only. You can view the data, but you can't update it.
To connect to a database
In Solution Explorer, open the shortcut menu for the Data Sources node, and then choose Add Data Source.
The Attach Data Source wizard opens.
In the Attach Data Source wizard, choose OData Service, and then choose Next.
On the Enter Connection Information page, in the OData Source Address box, enter
Under Login Information, choose the Windows Authentication option button, and then choose Next.
On the Choose your Entities page, expand the Entities node.
Choose the Customer, Order, Order_Detail, and Product tables, and then choose Finish.
The NorthwindEntitiesData data source is added to the project, and entities are created for Customers, Orders, Order_Details, and Products.
In this lesson, you connected to the Northwind sample database, which was exposed through an Open Data Protocol (OData) service. For your own applications, you’ll need to 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, SAP, or WCF RIA Service as a data source. For a LightSwitch application, you can connect to data from a SQL Server database, from a SharePoint list, from a SAP NetWeaver Gateway, or from a Windows Communication Foundation Rich Internet Application (WCF RIA) service that’s designed for LightSwitch and hosted on a web server. See How to: Connect to Data.
In the next lesson, you’ll learn how to work with the data entities that you just created.
Next lesson: Customizing Entity Fields
Working with Data
How to: Connect to Data
Connect to a SharePoint List
Guidelines for Creating WCF RIA Services for LightSwitch
Extensions: Adding New Capabilities to LightSwitch