Microsoft LightSwitch Application using SQL Azure Database

Exclusive offer: get 50% off this eBook here
.NET Compact Framework 3.5 Data Driven Applications

.NET Compact Framework 3.5 Data Driven Applications — Save 50%

Build robust and feature-rich mobile data-driven applications with the help of real-world examples

$29.99    $15.00
by Jayaram Krishnaswamy | August 2010 | Microsoft Web Development

Microsoft LightSwitch is the latest standalone product from Microsoft belonging to the Visual Studio suite of products. It is expressly targeted to tech savvy but non-programmers (hobbyists) to develop line of business applications using Microsoft Databases or other sources. This is a new game plan by Microsoft to catch a wider audience as well as encourage them to use its cloud offerings. If priced right and supported well, this may help businesses to develop applications on their own or call in junior level programmers with some knowledge of individual technologies like databases, user interfaces, mouse clicks, window navigation etc.

The LightSwitch Beta 1 was out on August 23rd for the general public while it has been used by MSDN members and Microsoft insiders for couple of months. This article by Jayaram Krishnaswamy shows how you may download and install this program. The article also shows how you may develop a simple database application using this product retrieving data from the Cloud hosted relational database, the SQL Azure.

(For more resources on Microsoft, see here.)

Your computer has to satisfy the system requirements that you can look up at the product site (while downloading) and you should have an account on Microsoft Windows Azure Services. Although this article retrieves data from SQL Azure, you can retrieve database from a local server or other data sources as well. However it is presently limited to SQL Server databases.

The article content was developed using Microsoft LightSwitch Beta 1, SQL Azure database, on an Acer 4810TZ-4011 notebook with Windows 7 Ultimate OS.

Installing Microsoft LightSwitch

The LightSwitch beta is now available at this site here, the file name is vs_vslsweb.exe: http://www.microsoft.com/visualstudio/en-us/lightswitch

When you download and install the program you may get into the problem that some requirement not being present. While installing the program for this article there was an initial problem. The Microsoft LightSwitch requires Microsoft SQL Server Compact 3.5 SP2. While this was already present on the computer it did not recognize. However in addition to SP2 there were also present the Microsoft SQL Server Compact 3.5 SP1 as well as SQL Server Compact 4.0. After removing Microsoft SQL Server Compact SP1 and SP2 the program installed without further problems after installing SQL Server Compact 3.5 SP2 again. Please review this link (http://hodentek.blogspot.com/2010/08/are-you-ready-to-see-light-with.html) for more detailed information. The next image shows the Compact products presently installed on this machine.

Microsoft LightSwitch Application using SQL Azure Database

Creating a LightSwitch Program

After installation you may not find a shortcut that displays an icon for Microsoft LightSwitch. But you may find a Visual Studio 2010 shortcut as shown. The Visual Studio 2010 Express is a different product which is free to install. You cannot create a LightSwitch application with Visual Studio 2010 Express.

Microsoft LightSwitch Application using SQL Azure Database

Click on Microsoft Visual Studio 2010 shown highlighted. This opens the program with a splash screen. After a while the user interface displays the Start Page as shown. You can have more than one instance open at a time.

Microsoft LightSwitch Application using SQL Azure Database

The Recent Projects is a catalog of all projects in the Visual Studio 2010 default project directory. Just as you cannot develop a LightSwitch application with VS 2010 Express, you cannot open a project developed in VS 2010 Express with the LightSwitch interface as you will encounter the message shown.

Microsoft LightSwitch Application using SQL Azure Database

This means that LightSwitch projects are isolated in the development environment although the same shell program is used.

When you click File | New Project you will see the New Project window displayed as shown here. Make sure you set the target to .NET Framework 4.0 otherwise you may not see any projects. It is strictly .NET Framework 4.0 for now. Also trying to create, File | New web site will not show any templates no matter what the .NET Framework you have chosen. In order to see Team Project you must have a Team Foundation Server present. In what follows we will be creating LightSwitch application (default name is Application1 for both C# and VB).

From what is displayed you will see more Silverlight project templates than LightSwitch project templates. In fact you have just one template either in C# or in VB.

Microsoft LightSwitch Application using SQL Azure Database

Highlight LightSwitch Application (VB) and change the default name from Application1 to something different. Herein it is named SwitchOn as shown.

Microsoft LightSwitch Application using SQL Azure Database

If you were to look at the project properties in the property window you will see that the filename of the project is SwitchOn.lsproj. This file type is exclusively used by LightSwitch. The folder structure of the project is deceptively simple consisting of Data Sources and Screens.

.NET Compact Framework 3.5 Data Driven Applications Build robust and feature-rich mobile data-driven applications with the help of real-world examples
Published: April 2010
eBook Price: $29.99
Book Price: $49.99
See more
Select your format and quantity:

Read more about this book

(For more resources on Microsoft, see here.)

Accessing data on SQL Azure

Although you can connect to any of the SQL Server databases or other sources, we will make a connection to the SQL Azure database. SQL Azure database services supports creating a SQL Server instance in the cloud which you would normally set up after creating an account to use the services. Once you create an account you can provision a SQL Azure instance wherein you can go in and create objects. You would normally create the database in the SQL Azure portal and create other objects after connecting to it from client applications. In the present case a SQL Azure database has been created called Bluesky. Bluesky database on SQL Azure server instance with the name xxxxxxxx.database.windows.net will be used where xxxxxxxx is an account specific random string assigned by Windows Azure Services.

Click on Attach to external database in the left side of the previous screen. This brings up the Attach Data Source Wizard as shown. You could use a database, or SharePoint or WCF RIA Service as the source of your data.

Microsoft LightSwitch Application using SQL Azure Database

Choose Database by clicking on it and click Next >. This brings up the Connection Properties window as shown. In this beta version you can only connect to Microsoft SQL Servers with only one provider, the Microsoft SQL Server SqlClient. Of course you can connect to any of SQL Server 2008 R2, SQL Express as well as SQL Azure. Since there are no SQL Server versions older than 2008 they are not seen in the drop-down. Also SQL Azure is not displayed as a connection is yet to be made.

Microsoft LightSwitch Application using SQL Azure Database

Provide the following information in the text boxes and the choices:

Server name: xxxxxxxx.database.windows.net

Choose Use SQL Server Authentication and provide:

Username: <user name of your SQL Azure database>

Password: <Password for the above username>

When you browse for the database name you may not see it unless you test connectivity. Choose or enter database name (Bluesky in this case) and click OK. Make sure to test the connection.

This opens up your database on SQL Azure and displays the objects such as tables etc. On the Bluesky database there are a number of tables as shown.

Microsoft LightSwitch Application using SQL Azure Database

Accept the default Data Source Name after choosing table(s) from the list. Herein the Employees table has been chosen. Click Finish. The design view of the table(Metadata) will be displayed as shown in the next image.

Microsoft LightSwitch Application using SQL Azure Database

Choosing any one Column such as TitleOfCoursey, the properties of the column can be reviewed in the property window as shown. Also you have the support to carry out a number of tasks such as adding a Relationship based on the entity; a Computed Property; a Query as well as screen based on the entity. For now we are not taking any of these actions.

Microsoft LightSwitch Application using SQL Azure Database

The Display name for the column TitleOfCourtsey (shown highlighted) was changed to Nick Name after deleting the default. You can make changes in the properties window for most of the displayed items. With this display name change it is expected that in the final display the column name would be Nick Name.

Microsoft Silverlight 4 and SharePoint 2010 Integration Techniques, practical tips, hints, and tricks for Microsoft Silverlight 4 interactions with SharePoint 2010 in this book and eBook
Published: July 2010
eBook Price: $32.99
Book Price: $54.99
See more
Select your format and quantity:

Read more about this book

(For more resources on Microsoft, see here.)

Adding a screen to the project

Right click the Screens folder and choose Add Screen.... This pops-up the Add New Screen window as shown. In fact there are 4 different types of screens that you can choose from. Here is the New Data Screen window. The details of where each of the screens can be used are explained in the images.

Microsoft LightSwitch Application using SQL Azure Database

The next screen is meant for those who want to search the table once the screen is designed. There is a search box at the top right corner of the window.

Microsoft LightSwitch Application using SQL Azure Database

The next one shows the type of screen used for parent-child details. The child records are pulled from other screens.

Microsoft LightSwitch Application using SQL Azure Database

The next screen shows the List and Details, a variation of the same but with different controls.

The screens that are prefabricated represent therefore the real world scenarios people usually encounter in designing user interfaces.

Microsoft LightSwitch Application using SQL Azure Database

For this article, we choose one of them shown here. The default name of the screen has been changed to Employee_Brief as shown.

Microsoft LightSwitch Application using SQL Azure Database

After making the choice of the screen when you click OK, the screen will be added to the Screens folder as shown. When you click on Employee_Brief in the project folder you will see Employee_Brief in the Vertical Stack layout. There are other options such as Modal Window, Horizontal Stack, and Two Columns Stack. You will also see that the Command Bar is greyed out.

Click OK. The Search type screen will be added with its property displayed as shown.

Microsoft LightSwitch Application using SQL Azure Database

Presently there is no data binding. Click Add Data Item menu of Employee_Brief tab. The Add Screen Item window is displayed as shown with default Queries as shown. Click Employees with the Return Type Employee*(Select All).

Microsoft LightSwitch Application using SQL Azure Database

Click OK. The EmployeesCollection gets added to the user interface as shown with its properties displayed.

Microsoft LightSwitch Application using SQL Azure Database

The next image shows the same in tree view.

Microsoft LightSwitch Application using SQL Azure Database

Now click on EmployeeCollection in the above image just above the SelectedItem. The data will be added to a DataGrid inserted into the screen as shown in the next image with each employee data as a DataRow.

Microsoft LightSwitch Application using SQL Azure Database

Displaying the screen

We are almost done. Build the project. This takes a considerable amount of time. After it succeeds click F5. The project will run and after quite a while it gets displayed as shown in the development web server as shown. Notice that the column name is now displaying Nick Name (and not the default TitleOfCourtsey).

Microsoft LightSwitch Application using SQL Azure Database

Now test the search functionality as shown in the next image. It does bring up the right item pretty quickly. The Last Name Suyama was searched by entering the Last Name in the search box.

Microsoft LightSwitch Application using SQL Azure Database

Summary

The article describes LightSwitch, the latest rapid application development tool from Microsoft. The article describes in detail retrieving and displaying data on a SQL Azure database. The software is still in beta and some of the functions are not fully implemented. For example you cannot create a web site project; you can add a Toolbox but all tools are disabled; limited to one data source provider , etc. The tool looks very promising but the Build and Run processes take a long time (perhaps my overloaded, overheated computer). It is interesting that not a line of code was written. One could also write code for the various events that happen in the life time of screen and data, but then the promise made for non-programmers cannot be honored. May be we revisit writing code next time around.



About the Author :


Jayaram Krishnaswamy

Jayaram Krishnaswamy studied at the Indian Institute of Science in Bangalore India and Madras University in India and taught at the Indian Institute of Technology in Madras. He went to Japan on a Japanese Ministry of Education Research scholarship to complete his PhD in Electrical Engineering from Nagoya University. He was a Post-Doctoral Fellow at Sydney University in Australia; a Government of India Senior Scientific Officer at the Indian Institute of Science in Bangalore and Indian Institute of Technology at Kanpur; a Visiting Scientist at the Eindhoven Institute of Technology in the Netherlands; a visiting Professor of Physics at the Federal University in Brazil; an Associate Research Scientist at a government laboratory in São Jose dos Campos in São Paulo, Brazil; a visiting scientist at the National Research Council in Ottawa, Canada before coming to USA in 1985. He has also taught and worked at the Colorado State University in Fort Collins and North Carolina State University in Raleigh, North Carolina. He worked with Northrop Grumman Corporation on a number of projects related to high energy electron accelerators and Free Electron Lasers. These projects were undertaken at the Brookhaven National Laboratory in Long Island and in the Physics Department at Princeton University. He has over 80 publications in refereed and non-refereed publications and 8 issued patents. He is fluent in Japanese and Portuguese and lives in Honolulu, Hawaii, USA.

He has been working in IT-related fields since 1997. He was once a Microsoft Certified Trainer in Networking and a Siebel Certified developer. He has worked with several IT related companies, such as the Butler International in their Siebel practice, with several IBM sub-contractors and smaller companies. Presently he is active in writing technical articles in the IT field to many online sites such as http://CodeProject.com, http://APSFree.com, http://DevShed.com, http://DevArticles.com, http://OfficeUsers.org, http://ASPAlliance.com, Egghead Café, http://SSWUG.org, Packt Article Network, http://databasedev.co.uk, http://cimaware.com, and many others. Between 2006 and 2010 he wrote more than 400 articles mostly related to database and web related technologies covering Microsoft, Oracle, Sybase, ColdFusion, Sun, and other vendor products.

He has written four books all published by Packt related to Microsoft Database and Application Development: SQL Server Integration Services Using Visual Studio 2005, Learning SQL Server Reporting Services 2008, Microsoft SQL Azure; Enterprise Application Development, and Microsoft Visual Studio Lightswitch Business Application Development. He regularly writes for his four blogs on Blogger; http://Hodentek.blogspot.com, http://HodentekHelp.blogspot.com, http://HodentekMobile.blogspot.com, and http://HodentekMSSS.blogspot.com. He received the 2011 Microsoft Community Contributor award.

Contact Jayaram Krishnaswamy

Books From Packt


Microsoft Silverlight 4 Business Application Development: Beginner’s Guide
Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

Microsoft Visio 2010 Business Process Diagramming and Validation
Microsoft Visio 2010 Business Process Diagramming and Validation

Microsoft Office Live Small Business: Beginner’s Guide
Microsoft Office Live Small Business: Beginner’s Guide

Microsoft Windows Workflow Foundation 4.0 Cookbook
Microsoft Windows Workflow Foundation 4.0 Cookbook

WCF 4.0 Multi-tier Services Development with LINQ to Entities
WCF 4.0 Multi-tier Services Development with LINQ to Entities

Microsoft Silverlight 4 Data and Services Cookbook
Microsoft Silverlight 4 Data and Services Cookbook

Applied Architecture Patterns on the Microsoft Platform
Applied Architecture Patterns on the Microsoft Platform

Expert Cube Development with Microsoft SQL Server 2008 Analysis Services
Expert Cube Development with Microsoft SQL Server 2008 Analysis Services


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
S
x
x
D
Z
P
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software