programming4us
programming4us
WEBSITE

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

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
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.

NOTE

If you need to download the Windows Azure Tools, go to the Microsoft Download Center at www.microsoft.com/downloads/. 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

NOTE

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:

    <connectionStrings>
    <add
    name="Connection1"
    providerName="System.Data.SqlClient"
    connectionString="Server=tcp:jt4y4mmglp.database.windows.net;
    Database=EnzoLog;User ID=test@jt4y4mmglp;
    Password=yourPasswordHere;
    Trusted_Connection=False;Encrypt=True;"/>
    </connectionStrings>

    NOTE

    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" >
</asp:SqlDataSource>

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.

Other  
 
Top 10
Free Mobile And Desktop Apps For Accessing Restricted Websites
MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
TOYOTA CAMRY 2; 2.5 : Camry now more comely
KIA SORENTO 2.2CRDi : Fuel-sipping slugger
How To Setup, Password Protect & Encrypt Wireless Internet Connection
Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
Backup & Restore Game Progress From Any Game With SaveGameProgress
Generate A Facebook Timeline Cover Using A Free App
New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
- Messages forwarded by Outlook rule go nowhere
- Create and Deploy Windows 7 Image
- How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
- Creating and using an unencrypted cookie in ASP.NET
- Directories
- Poor Performance on Sharepoint 2010 Server
- SBS 2008 ~ The e-mail alias already exists...
- Public to Private IP - DNS Changes
- Send Email from Winform application
- How to create a .mdb file from ms sql server database.......
programming4us programming4us
programming4us
 
 
programming4us