building a simple sql azure appbandgap.cs.rice.edu/classes/comp410/resources/using azure... · web...

18
Demo Script Building a Simple SQL Azure App Lab version: 2.0.0 Last updated: 7/6/2022

Upload: others

Post on 06-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

Demo ScriptBuilding a Simple SQL Azure App

Lab version: 2.0.0

Last updated: 5/18/2023

Page 2: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

CONTENTS

OVERVIEW................................................................................................................................................. 3Key Messages......................................................................................................................................... 3

Key Technologies.................................................................................................................................... 3

Time Estimates........................................................................................................................................ 4

SETUP AND CONFIGURATION................................................................................................................. 4Task 1 –Run the dependency checker.................................................................................................4

Task 2 – Ensure that the HolTestDB and HoLTestUser are created and configured............................5

Task 3 – Ensure that the AdventureWorksLT2008 Database is attached to the local SQL Server........5

Task 4 – Add database data and schema to SQL Azure.......................................................................5

DEMO FLOW.............................................................................................................................................. 5

OPENING STATEMENT............................................................................................................................. 6

STEP-BY-STEP WALKTHROUGH.............................................................................................................7Create a New web Role project...............................................................................................................7

Add GridView to control with SQL Datasource........................................................................................8

Change Local SQL connection to SQL Azure........................................................................................14

SUMMARY................................................................................................................................................ 15

Page 3: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

Overview

This document provides setup documentation, step-by-step instructions, and a written script for showing a demo of SQL Azure. This document can also serve as a tutorial or walkthrough of the technology. In this demo, you will look at creating a simple Windows Azure Web Role that connects to SQL Azure to retrieve data and display it. For additional demos of the Windows Azure platform, please visit http://www.azure.com.

Note: In order to run through this demo, you must have a SQL Azure developer account. For more information on how to purchase an account, visit the SQL Azure Portal at http://www.microsoft.com/windowsazure/sqlazure/.

Key Messages

In this demo you will see three key messages:

1. Windows Azure and SQL Azure are fully compatible

2. SQL Azure behaves in a similar way to the standard SQL Server 2008 instance for development

3. You can develop solutions quickly when utilizing an existing local database

Key Technologies

This demo uses the following technologies:

1. SQL Azure

2. Visual Studio 2010

Page 4: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

Time Estimates

Estimated time for setting up and configuring the demo: 40 min

Estimated time to complete the demo: 10 min

Setup and Configuration

The setup and configuration for this demo involves the following tasks:

1. Run the dependency checker.

2. Ensure that the HolTestDB and HoLTestUser are created and configured.

3. Ensure that the AdventureWorksLT2008 Database is attached to the local SQL Server.

4. Add database schema and data to SQL Azure.

Task 1 –Run the dependency checker

This demo does not have any advanced configuration requirements. You simply need to have the prerequisites installed and have an account for SQL Azure. For more information on how to purchase an account, visit the SQL Azure Portal at http://www.microsoft.com/windowsazure/sqlazure/.

The following steps describe how to run the Dependency Checker utility included with the demo to verify that you have the prerequisite components. You can skip this exercise if you are confident that the prerequisites are properly installed and configured.

1. Open a Windows Explorer window and browse to the demo’s Source\Script folder.

2. Double-click the Dependencies.dep file in this folder to launch the Dependency Checker tool and install any missing prerequisites.

3. If the User Account Control dialog is shown, confirm the action to proceed.

Page 5: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

Note: This process may require elevation. The .dep extension is associated with the Dependency Checker tool during its installation. For additional information about the setup procedure and how to install the Dependency Checker tool, refer to the Setup.docx document in the Assets folder of the training kit.

Task 2 – Ensure that the HolTestDB and HoLTestUser are created and configured

You should ensure that you have followed the steps in the Demo scripts for 'Connecting to SQL Azure' and ' Managing Logins and Security in SQL Azure'. Specifically you need to have created the HoLTestDB database and HolTestUser login and user account and you must have granted the role db_owner to the HoLTestUser login.

Task 3 – Ensure that the AdventureWorksLT2008 Database is attached to the local SQL Server

Ensure that you have attached the AdventureWorksLT2008 database to your local SQL Server before beginning. This can be found here: http://www.codeplex.com/MSFTDBProdSamplesYou should download and execute the appropriate SQL2008.AdventureWorks_all_Databases.<ProcessorArchitecture>.msi for your processor architecture- x86, x64 or ia64.

Task 4 – Add database data and schema to SQL Azure

Work through Exercise 1 of the lab Migrating Data to SQL Azure to add the required data to the HoLTestDB. You will need both the schema and the data added from this lab.

Demo Flow

The step-by-step guide in this document will walk you through the following steps:

Page 6: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

Figure 1Demo Flow

Opening Statement

In this demo, you will learn how to connect a basic Azure web role to SQL Azure. You will see the symmetry between on-premise and database development and SQL Azure.

1. Initally you will create a new Azure web role project with a single page

2. A datasource will be added linking to a local database

Page 7: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

3. The database connection will be changed to connect to SQL Azure

Note: A completed solution can be found in the code folder of this demo.

Step-by-Step Walkthrough

This demo is composed of the following steps:

1. Create a New Web Role Project

2. Add a GridView control with a SQL Datasource connected to the local SQL Server

3. Change the SQL connection to SQL Azure

Create a New web Role project

In this first step, you will demonstrate how to create a web role project using the latest CTP of the Windows Azure SDK.

Action Script Screenshot

1. Open Visual Studio 2010. Start > All Programs > Microsoft Visual Studio 2010

We’re going to be using Microsoft Visual Studio 2008 to work with SQL Azure.

Page 8: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

2. Open the New Project dialog. File > New > Project

3. Create a new Web Cloud Service using the configuration setting from the screenshot below.

We need to create a new Web Role Cloud services project.

We can use the Cloud Service template provided in the November 2009 CTP.

4. Now Select ASP .NET Web Role from the list and click the arrow.

5. Rename the WebRole to AdventureWorksWeb by clicking the pencil icon

6. Click the OK button to start creating the project.

We can now select the parts of the cloud service project we want to include.

We will need a web role. Let’s rename it to something sensible.

Add GridView to control with SQL Datasource

This segment will demonstrate adding a basic datagrid to a web page and creating a datasource to the local database. This will demonstrate how SQL Azure works like any other SQL database when using existing controls such as the GridView.

Action Script Screenshot

Page 9: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

1. Ensure that you are viewing the Default.aspx page in Design View by clicking the Design button.

We now will view the default webpage for the site in the designer.

2. Drag and drop a GridView control from the Data section of the Toolbox.

We will add a GridView control to the page to display some information from the database.

3. From the SmartTag on the GridView you just created choose New data source…

Normally we would simply configure a datasource at this point using the Wizard. However, the Add Connection dialog in Visual Studio does not currently work in this ctp, so for this exercise we will need to manually create a connection string first. To simplify debugging we will start by testing against our local SQL Server 2008 instance before changing our connection string to point to SQL

Page 10: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

Azure.

Using the smart tag, we can add a new datasource to this GridView.

4. In theWizard choose a Data Source Type of Database and leave the default ID.

Select Database for the source of the data.

Use the default name for the source.

Page 11: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

5. In the Configure Data Source Wizard click New Connection.

6. In the Choose Data Source dialog select Microsoft SQL Server and click Continue.

7. In the Add Connection dialog configure a connection to your local copy of AdventureWorksLT2008

8. Press Test Connection you should receive a dialog indicating success

9. Click OK to close the Add Connection dialog box.

10. Click Next to continue through the Wizard

We now want to create the connection to the local database, we can do this through the configure data source wizard.

We will select our local server and the AdventureWorks database.

We now will check to see if the connection has been configured correctly.

Page 12: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

11. Ensure that the Yes, save this connection as in the checkbox and use the name AdventureWorksLT2008ConnectionString

12. Click Next

We will name this connection as AdventureWorksLT2008ConnectionString, this will make it easier for us to find it later for editing.

13. Choose the table named Customer and check the FirstName, LastName, CompanyName and EmailAddress.

We will pick the Customer table from the drop down and select the columns we want to display.

This step would not be possible were we connected to SQL Azure as the current CTP does not currently work with Visual Studio to allow object browsing.

Page 13: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

14. Select the SELECT Statement at the bottom of the dialog and press Ctrl-C to copy to the clipboard.

15. Click the radio button to Specify a custom SQL statement of stored procedure

16. Click Next button17. Paste the statement you copied into

the SQL Statement box.18. Change the statement to read

SELECT [FirstName], [LastName], [CompanyName], [EmailAddress] FROM [SalesLT].[Customer]

19. Press Next

We now need to copy the generated SELECT statement, this is because the table is in the schema SalesLT.

We can now select to use a custom query and paste the generated sql into the next screen.

Now we can add the required schema to the table reference.

20. Press Test Query and you should see results returned.

21. Click Finish

Now we can test our select query to see if we will receive any results.

Page 14: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

22. Press F5 to run the application in the Azure Development Fabric

We will want to see this page working so we can press F5 to run this in our development fabric.

This allows us to see what it would look and how it will behave behave in Windows Azure without having to publish it to the cloud.

Change Local SQL connection to SQL Azure

We will now demonstrate changing the current connection to the SQL Azure database

Action Script Screenshot

1. Close the browser and return to Visual Studio

2. Open the web.config file

The next step is to get the application to retrieve the data from SQL Azure.

To do this we will edit the connection string inside the Web.config

Find the connectionStrings section and modify the connection string to the following:

<add name="AdventureWorksLT2008ConnectionString"

connectionString="Initial Catalog=HoLTestDB;

All that needs to be done is to change the source and add our ID and Password to the connection string. We will also need to remove the Integrated security option.

Page 15: Building a Simple SQL Azure Appbandgap.cs.rice.edu/classes/comp410/resources/Using Azure... · Web viewBuilding a Simple SQL Azure App Lab version:2.0.0 Last updated:8/5/2010 Contents

Data Source=REPLACE_SERVER_NAME.database.windows.net;encrypt=true;User ID=HoLTestUser;Password=REPLACE_HoLTestUser_PASSWORD;

TrustServerCertificate=true;"

providerName="System.Data.SqlClient" />

3. Press F5 to run the application once again.

This time the list of Customers is being retrieved from SQL Azure.

Summary

In this demonstration, we saw just how easy it was to create a simple Windows Azure application in the development environment and then connect this to SQL Azure to execute the same queries.