Articles → Light Switch 2011 → Connect To External Database In Lightswitch 2011

Connect To External Database In Lightswitch 2011






Software Requirement




  1. Visual studio 2010 is installed on your machine.
  2. Visual Studio 2010 service pack 1 is installed on your machine.
  3. Microsoft Visual Studio Light switch 2011 is installed on your machine.
  4. Silverlight runtime version 4 or 5 is installed on your machine

Prerequisite Knowledge




  1. How to create a new project using visual studio?
  2. How to create database, tables etc. in MS SQL server?
  3. What are screens and entities in lightswitch?
  4. How to create a screen in lightswitch application?

Steps Of Execution




  1. Create a new project
  2. Create a new database
  3. Connect with the existing database
  4. Create a new screen



Create A New Project




Picture showing the sample lightswitch project in visual studio
Click to Enlarge


Create A New Database




Picture showing the country, state and city tables in sql server database
Click to Enlarge


Connect With The Existing Database




  1. Right click on the ‘Data sources’ folder and click ‘Add Data source..’.
  2. A window appears as shown in figure below. From the window select ‘Database’ and click on next
  3. Picture showing the wizard to select the data source type
    Click to Enlarge

  4. A window appears to allow user to enter the database credentials.
  5. Picture showing a popup window to enter the database credentials and validate them
    Click to Enlarge

  6. Once the credentials are entered and database is selected click on Ok.
  7. Another window appears which displays the list of tables in the selected database (and views if any)
  8. Picture showing the list of tables to be selected from the data source
    Click to Enlarge

  9. Click on Finish.
  10. A popup window appears for giving warning about the issues in data source
  11. Picture showing the warning message when trying to add the table in the lightswitch project
    Click to Enlarge

  12. Click continue
  13. Data source is added in the project. See the screen shot below
  14. Picture showing the country, state and city lightswitch tables in visual studio solution explorer
    Click to Enlarge

Create A New Screen




Picture showing a popup window for adding a new data screen
Click to Enlarge


Output




Picture showing the data coming from the sql server database tables
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, August 7, 2013

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250