Windows Azure and ASP.NET : Creating a Windows Azure Project

2/11/2011 11:43:32 AM
Let's create a simple Windows Azure application in Visual Studio that displays a list of database users. The Windows Azure project is an ASP.NET application created with a special project template: Cloud.

1. Configuring Your Development Environment

You must first configure the Windows Azure Tools on your development environment to be able to develop a Windows Azure ASP.NET application. You must be running Windows Server 2008 or higher, or Windows Vista or higher. The Windows Azure Tools provide a runtime environment on your machine that allows you to develop and test a Windows Azure project. It basically runs a local cloud for development purposes. After it's installed, you see a new project type: Cloud. When creating your project in Visual Studio, you can select the Cloud project type; an option to install the Windows Azure Tools is available the first time you do so.


If you need to download the Windows Azure Tools, go to the Microsoft Download Center at Search for Azure Tools, and pick the version that applies best to your Visual Studio version. Make sure to download and install this extension.

2. Creating Your First Visual Studio Cloud Project

To create a Visual Studio cloud project, follow these steps:

  1. Start Visual Studio in elevated mode (as an Administrator). To do so, right-click Microsoft Visual Studio 2008 or Microsoft Visual Studio 2010, and select "Run as administrator," as shown in Figure 1. Running as Administrator is required by the Windows Azure simulation tools that give you the ability to test your Azure solution locally.

    Figure 1. Start Visual Studio in elevated mode.

If you don't start Visual Studio in elevated mode, you're able to create the project but you can't run it. If you try, you get an error message telling you to restart Visual Studio, as shown in Figure 2.

Figure 2. Error trying to run an Azure project when not in elevated mode

  1. Choose File → New → New Project to bring up the window shown in Figure 3 for Visual Studio 2008 or Figure 9-8 for Visual Studio 2010. Select the Cloud project type (Cloud Service in Visual Studio 2010), and choose Windows Azure Cloud service.

    Figure 3. Cloud project type in Visual Studio 2008
    Figure 4. Cloud Service project type in Visual Studio 2010
  2. Enter a name for your project, and click OK. A new screen comes up (see Figure 5) in which you can select a role for your application. The role of your ASP.NET application dictates its primary purpose and what you're able to do with the project. The following roles are available:

    • ASP.NET Web Role. Lets you create a web site with ASP.NET.

    • ASP.NET MVC 2 Web Role. Lets you create an MVC 2 web application (only available in Visual Studio 2010).

    • WCF Web Service Role. Allows you to create a WCF service in Windows Azure.

    • Worker Role. Equivalent to a background service in Windows Azure that has no user interface.

    • CGI Web Role. Lets you create a web application using a technology other than ASP.NET, such as Python.

    Figure 5. Role Types in Visual Studio 2010
  3. For this example, select the first option (ASP.NET Web Role), and click the right arrow (). Doing so adds a new ASP.NET web role in the list of services, named of WebRole1.

  4. To change the name, select WebRole1 and press the F2 key or click the Edit link. To see the Edit link, place your mouse somewhere on the WebRole1 service list item: you see two icons come up on the right. The first one (with the pencil) allows you to edit the name, and the second lets you remove this web role (see Figure 6).

    Figure 6. Editing the web role's name
  5. Change the name to wrAzureExample, and press the Enter Key. Don't use AzureExample as the web role name, or there will be a conflict with the solution name provided earlier. The web role should now look like Figure 7.

    Figure 7. Web role name changed
  6. Click OK.

At this point, you've created a new cloud solution. Solution Explorer looks a little different than it does for a typical ASP.NET project. Your cloud solution contains two projects: the AzureExample project and the wrAzureExample web role, which is itself a project, as shown in Figure 8. The AzureExample project contains configuration files that will be deployed later in Windows Azure.

Figure 8. Project layout for the ASP.NET web role


At the time of this writing, Windows Azure supports .NET 3.5 SP1 and .NET 4.0.

3. Connecting a GridView to SQL Azure

Continue the example by following these steps:

  1. Add a GridView control on the Default.aspx page, and connect it to a SQL Azure database. Although SqlDataSource is compatible with SQL Azure, it isn't possible to add a SqlDataSource and configure it with the built-in wizard; these steps next show you how to configure the SqlDataSource manually.

  2. Open the Default.aspx page, and select Design view.

  3. Drag a SqlDataSource from the Toolbox. Drag a GridView control on the page as well, and set its Data Source property to SqlDataSource1, as shown in Figure 9.

    Figure 9. Changing the GridView's Data Source property
  4. Open the web.config file, and enter your connection string. You need to add a connectionStrings node under the configuration node, as shown in the following example:

    Database=EnzoLog;User ID=test@jt4y4mmglp;


    Make sure to specify the user ID as <user name>@<server name>.

  5. Go back to the Default.aspx page, and change the SqlDataSource settings as follows by adding the ConnectionString and the SelectCommand settings manually.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Connection1 %>"
SelectCommand="SELECT uid, name FROM sys.sysusers ORDER BY 1" >

Running the project should give you output similar to that shown in Figure 10.

Figure 10. Running the solution locally and fetching data from SQL Azure

So far, you're running this project on the local machine. Although the Windows Azure Tools are required, this project doesn't use any of the Windows Azure storage options; it connects directly to a live SQL Azure database.

You could have created the same project as a regular ASP.NET application and obtained the same result. However, because you're about to deploy this project on Windows Azure, you must create a cloud project.

Top 10
Review : Sigma 24mm f/1.4 DG HSM Art
Review : Canon EF11-24mm f/4L USM
Review : Creative Sound Blaster Roar 2
Review : Philips Fidelio M2L
Review : Alienware 17 - Dell's Alienware laptops
Review Smartwatch : Wellograph
Review : Xiaomi Redmi 2
Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
Popular Tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8
Visit movie_stars's profile on Pinterest.