Local LightSwitch app and Windows Azure SQL Databases

Windows Azure, briefly, is a Microsoft public cloud platform that can be used to build and host web sites, virtual machines, SQL Server database, cloud services (i.e., worker and web roles), blob storage.  LightSwitch is a simple development tool built on top of familiar .NET technologies like VB/C#, Silverlight, and SQL Server. It allows development of line-of-business n-tier application very rapidly.

In this post, I will show how to create a local LightSwitch app which connects to a SQL Database in Windows Azure cloud.

First, we start by creating a SQL Server on Windows Azure. I go to Windows Azure portal then add new SQL Databases. If no SQL server has been created already, Azure will also create a new server.

image

After the database has been created, I can go to the dashboard to check the database status and get information of the database such as connection string. In my case, I want to have my machine to be able to connect to the SQL server, so I have to modify the firewall rule to let my IP address goes through. Azure does show my IP address which is very convenient.

Azure also provides me a very nice Silverlight-based SQL Azure Management Portal allowing me to manage the database online.

image

Indeed, the tool lets me create database tables, queries, and so on. I create a simple table called Blog with Title and Url columns which will be used with my local LightSwitch client. There is a lot of improvement alone from the portal/tool standpoint in the new Windows Azure. Now I am done with Azure side.

image

Next, I create a LightSwitch project and link to the external SQL Azure database has been created above. In the SQL Azure management portal, I can get the connection strings. It provide several types of connection strings, but what I need is only the protocol, server name and port in ADO.NET connection string. My database is displayed in the screen below after the server and login information are added. I can now select the Blog table that has been created with SQL Azure management portal.

image

image

In the LightSwitch Data designer, I now see Blog table. To utilize LightSwitch built-in specific URL validation, I can change the data type of the Url to Web Address, so LightSwitch can provide me more specific validation for this field. In this example, I create a screen using Editable Grid Screen template which creates a simple editable grid layout. LightSwitch also provides a designer allowing me to modify the screen layout.

image

image

image

My sample application is basically done. There are several ways to publish a LightSwitch application. In this post, I publish the LightSwitch application as a local desktop application. I can deploy my application as a web (Silverlight) application and let Windows Azure hosts it too. (Windows Azure SDK has to be installed.)

Once I deploy and install the application on my machine, I can now add the records to the Blog table.

image

Now, I go back to SQL Azure management portal, and I will see the record that I just added.

image

As you see, this is very effortless and no code at all. In few minutes, I now have a local Silverlight application that talks with SQL Azure database. Hosting database in the cloud also allows you to focus and enjoy more on the application itself instead of worrying about setting up a server, networking, OS, database, and so on!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s