Connecting to Data
In this lesson, you will learn how to connect to an external database to provide data for a LightSwitch application.
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
Connect to Data
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
In Solution Explorer, select the Data Sources node.
On the Project menu, click Add Data Source.
The Attach Data Source wizard opens.
In the Attach Data Source wizard, click Database and then click Next.
The Choose Data Source dialog box is displayed.
Note
If you have previously connected to a database in LightSwitch, this dialog box is not displayed and you can skip the next step.
In the Choose Data Source dialog box, click Microsoft SQL Server and then click Continue.
The Connection Properties dialog box is displayed.
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.
Expand the Tables node.
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.
Closer Look
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.
Next Steps
In the next lesson, you will learn how to work with the data entities that you just created.
Next lesson: Customizing Entity Fields
See Also
Tasks
Concepts
Guidelines for Creating WCF RIA Services for LightSwitch
Installing the Northwind Sample Database
Other Resources
Working with Data in LightSwitch (Guided Tour)