sql azure data-tier applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/lab.docx · web...

54
Hands-On Lab SQL Azure Data-tier Applications Lab version: 1.0.0 Last updated: 7/8/2022 Page 1

Upload: others

Post on 25-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Hands-On LabSQL Azure Data-tier ApplicationsLab version: 1.0.0

Last updated: 5/20/2023

Page 1

Page 2: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

CONTENTS

OVERVIEW................................................................................................................................................. 3

EXERCISE 1: DEPLOYING DATA-TIER APPLICATIONS TO A SQL AZURE DATABASE....................5Task 1 – Creating SQL Server Database Project...................................................................................5

Task 2 – Creating Database Schema....................................................................................................7

Task 3 – Publishing the Database to SQL Azure.................................................................................11

Verification........................................................................................................................................13

EXERCISE 2: UPGRADING DATA-TIER APPLICATIONS IN SQL AZURE...........................................15Task 1 – Inserting Sample Data to SQL Azure Database.....................................................................15

Task 2 – Creating a Storage Container to Export DAC Files................................................................16

Task 3 – Exporting a Data-Tier Application File from SQL Azure........................................................19

Task 4 – Upgrading a DAC Package....................................................................................................23

Task 5 – Deploying the Upgraded DAC Package................................................................................30

Verification........................................................................................................................................33

SUMMARY................................................................................................................................................ 35

APPENDIX A: CREATING A SQL AZURE SERVER...............................................................................35Task 1 – Retrieving your SQL Azure Server Name..............................................................................35

APPENDIX B: CREATING A STORAGE ACCOUNT...............................................................................42Task 1 – Creating a Storage Account..................................................................................................43

Page 2

Page 3: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Overview

SQL Azure Database supports a variety of mechanisms for deploying, versioning and migrating databases. You can use the traditional Transact-SQL script based approach to create your database objects, then populate your data either using scripts, BCP or SQL Server Integration Services. Schema upgrade scripts tend to be either hand coded or generated using additional tools. This approach is well known by SQL Server developers, but can be tedious for developers who are new to SQL Azure, especially when dealing with the complexities associated with database schema versioning.

Microsoft is addressing this complexity with a new framework called the Data-tier Application Framework, or DAC Fx, which makes it much easier to deploy, migrate and version your database schemas for SQL Server and SQL Azure. DAC Fx shipped initially with SQL Server 2008 R2, and support was soon added for SQL Azure. Since then, DAC Fx has evolved significantly and is an important part of the developer and managability story for SQL Azure. It is being integrated into developer tools like the SQL Server Data Tools, management tools like SQL Server 2012 Management Studio, and as a service accessible from the Windows Azure Management Portal.

Objectives

In this hands-on lab, you will learn how to:

Create a new SQL Server project using SQL Server Developer Tools Codename “Juneau” CTP3 (known as SSDT) to target SQL Azure.

Publish a Data-tier Application to SQL Azure using SSDT.

Export a .bacpac file into a blob storage container, using the Import/Export Service from the Azure Management Portal.

Upgrade the exported .bacpac file and update the SQL Azure database.

Prerequisites

You must have the following items to complete this lab:

Microsoft.NET Framework 4

SQL Server Developer Tools, Codename "Juneau" CTP 3 (SSDT)

Page 3

Page 4: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Exercises

This hands-on Lab includes the following exercises:

1. Deploying Data-tier Applications to a SQL Azure Database

2. Upgrading Data-tier Applications in SQL Azure

Estimated time to complete this lab: 45 minutes.

Page 4

Page 5: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Exercise 1: Deploying Data-tier Applications to a SQL Azure Database

In this exercise, you will learn how to create a new SQL Server Database project in SSDT, create a database definition schema and deploy it to SQL Azure.

Note: In order to complete this lab you will need a SQL Azure server to host the database. If you do not have one server created yet, use this appendix as a guide to do it: Appendix A: Creating a SQL Azure Server.

Additionally, if this is not the first time you run this exercise, you will need to run Reset.cmd script within the Source folder of this lab in order to clean up the SQL Azure database status. The script will prompt you for several pieces of information including a database name, which is “BooksInventory”.

Task 1 – Creating SQL Server Database Project

In this task you will create a SQL Server Database Project and set its target platform to SQL Azure.

1. Open SSDT. To do this, in Start | All Programs, click the Microsoft SQL Server Developer Tools shortcut.

2. From the File menu, choose New and then Project.

3. In the New Project dialog, select SQL Server in the Installed Templates list. Choose the SQL Server Database Project template, set the Name of the project to BooksInventory, set the location to \Source\Ex01-DeployingDACApp, change the solution name to Begin, and ensure that Create directory for solution is checked. Click OK to create the project.

Note: Make sure your project name is BooksInventory, as this is required in this lab to perform an upgrade to the database.

Page 5

Page 6: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 1Create SQL Server Database Project

4. You will update the project’s Target Platform and the Output Type. To do this, in Solution Explorer, right-click the BooksInventory project node, select Properties.

5. In the Project Settings tab, update the Target Platform to SQL Azure and make sure Data-tier Application within Output Types is checked.

Page 6

Page 7: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 2Updating SQL Server Database Project

6. Press Ctrl + S to apply changes.

Note: You can set the target platform for your database project to any release of SQL Server 2005 or above or SQL Azure.

By doing so, you can centralize your database development in one project, but publish it to multiple SQL Server platforms as the need arises.

SSDT also makes this task simple by being aware of your target platform and automatically detecting any error in your code (e.g., when you are using unsupported features for a project that is going to be published to SQL Azure).

For more information about this refer to msdn.

Task 2 – Creating Database Schema

Page 7

Page 8: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

In this task you will create the database schema that will be deployed to SQL Azure at the end of this exercise.

1. Add a new table to the Database project. To do this, right click in the BooksInventory project node, select Add and click Table.

Figure 3Add Table

2. In the Add New Item dialog, make sure Table template is selected and set the name to Authors. Click Add to create the table script.

Figure 4Create Table

Page 8

Page 9: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

3. In the BooksInventory node, within the Solution Explorer, double-click the Authors table we created in the previous step.

Figure 5Open Table Designer

4. In the Design tab within the Table Designer, add the following fields to the Authors table:

Name Data Type Allow Nulls? Is Primary Key?

Id Int No Yes

FirstName

nvarchar(50) No No

LastName

nvarchar(50) No No

5. Press Ctrl + S to apply changes.

6. Create a new table. To do this, repeat the first step of this task. This time, set the table name to Books and add the following fields:

Name Data Type Allow Nulls? Is Primary Key?

Id int No Yes

Title nvarchar(50) No No

ISBN nvarchar(13) Yes No

Price float Yes No

AuthorId int No No

Page 9

Page 10: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

7. Add a Foreign Key to the Books table. To do this, in the Table Designer, right-click the Foreign Keys node at the right pane and select Add New Foreign Key. Set its name to FK_Books_ToAuthors.

Figure 6Adding the Authors Foreign Key

8. To associate your Foreign Key to the Primary Key located in the Authors table, switch to the T-SQL tab and replace the CONSTRAINT line with the following highlighted code.

T-SQL

CREATE TABLE [dbo].[Books]( [Id] INT NOT NULL PRIMARY KEY, [Title] VARCHAR(50) NULL, [ISBN] VARCHAR(13) NULL, [Price] FLOAT NULL, [AuthorId] INT NULL, CONSTRAINT [FK_Books_ToAuthors] FOREIGN KEY ([AuthorId]) REFERENCES [Authors]([Id]))

9. Press Ctrl + S to apply changes.

10. Right-click the BooksInventory project node in the Solution Explorer and select Build.

11. After the build is completed, right-click again the BooksInventory project node in the Solution Explorer and select Open Folder in Windows Explorer. Browse to the Bin folder and then to Debug. Inside the folder, you will see the dacpac file that was generated in the previous step.

Page 10

Page 11: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 7Generated dacpac File in Bin folder

Task 3 – Publishing the Database to SQL Azure

In this task, you will use SSDT to deploy the database project to SQL Azure.

1. Right click the BooksInventory node within the Solution Explorer and select Publish.

2. In the Publish DAC dialog, click Edit… to set the database connection.

Figure 8Publishing DAC

3. In the Connection Properties dialog complete the Server Name with your SQL Azure server name (i.e. your-server-name.database.windows.net) and the User Name and Password with your SQL Azure credentials. Leave the Database Name with the default value. In this case we will use the same name as the project, but you can change it and use a different one.

Page 11

Page 12: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 9Connection Settings

4. Click OK to save settings.

5. Back on the Publish DAC dialog, click Publish to start publishing your project to SQL Azure.

Page 12

Page 13: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 10Publishing the Application

6. In the Output window you will see the Publishing progress. Wait until it finishes before running the verification.

Verification

In this task you will connect to SQL Azure to verify that the database was deployed correctly. To do this, you will use the SQL Server Explorer that is included with SSDT.

1. In the View menu, select Server Explorer.

2. In the Server Explorer pane, right-click the SQL Server node and select Add SQL Server. It will prompt a Connect to Server dialog. Fill it with your Server Name and Credentials and click Connect.

Figure 11

Page 13

Page 14: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Connecting to SQL Azure Server

3. In the Server Explorer pane expand the SQL Server node. Locate your SQL Azure Server and expand Databases folder. Locate the BooksInventory database we created in the previous task.

4. Expand Tables folder within BooksInventory database and verify that both Authors and Books tables were created.

Figure 12BooksInventory Verification

5. To see the DAC metadata registration, expand the Management node and the Data-tier Applications.

Figure 13Visualizing registered DAC Packages

6. Right-click the BooksInventory DAC and select Properties. You can view the DAC metadata registered in SQL Azure.

Figure 14Visualizing DAC metadata

Page 14

Page 15: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Exercise 2: Upgrading Data-tier Applications in SQL Azure

In this exercise, you will export a Data-Tier Application Component (DAC) from your SQL Azure Database, apply some changes in SSDT and publish the DAC back to the SQL Azure database.

Note: This exercise requires the database you created in the Exercise 1. Also it requires an Azure Storage Account. If you don’t have one, refer to the Appendix B: Creating a Storage Account.

Make sure you added the necessary Firewall Rules to allow you access to the SQL Azure Server using Management Studio. Also add the Microsoft Services rule (IP Address range “0.0.0.0” to “0.0.0.0”)

Task 1 – Inserting Sample Data to SQL Azure Database

In this task you will insert sample data to your SQL Azure database. This data will be exported in the following tasks, as a bacpac package. Using SSDT, you will execute a script file in order to generate the sample data.

1. Open SSDT. To do this, in Start | All Programs, click the Microsoft SQL Server Developer Tools shortcut.

2. In the View menu, select Server Explorer.

3. If your SQL Azure server is present in the list, skip this step. Otherwise, in the Server Explorer pane, right-click the SQL Server node and select Add SQL Server. It will prompt a Connect to Server dialog. Fill it with your Server Name and Credentials and click Connect.

4. Expand the Databases node and right-click the BooksInventory database and select New Query.

5. Insert the following code to the query window and execute it by pressing ALT+X.

T-SQL

-- DELETE SAMPLE DATADELETE FROM BooksGODELETE FROM Authors

-- INSERT AUTHORS SAMPLE DATA

Page 15

Page 16: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

INSERT INTO Authors (Id, FirstName, LastName) VALUES (1, 'Guy', 'Gilbert')GOINSERT INTO Authors (Id, FirstName, LastName) VALUES (2, 'Kevin', 'Brown')GOINSERT INTO Authors (Id, FirstName, LastName) VALUES (3, 'Roberto', 'Tamburello')GO

-- INSERT BOOKS SAMPLE DATAINSERT INTO Books (Id, Title, ISBN, Price, AuthorId) VALUES (1, 'Silicon Valley Gastronomic Treats', '11111A', 12, 1)GOINSERT INTO Books (Id, Title, ISBN, Price, AuthorId) VALUES (2, 'You Can Combat Computer Stress!', '11112B', 9, 1)GOINSERT INTO Books (Id, Title, ISBN, Price, AuthorId) VALUES (3, 'Sushi, Anyone?', '12224F', 7, 2)GOINSERT INTO Books (Id, Title, ISBN, Price, AuthorId) VALUES (4, 'But Is It User Friendly?', '234AB34F', 3, 3)

Task 2 – Creating a Storage Container to Export DAC Files

In this task you will use a free software application named Azure Storage Explorer in order to create a new storage container. This container will be used by the Import / Export Service, from the Management Portal, to export a .bacpac file. This file will be used later in this exercise to apply changes to our current database schema.

Note: If not installed, download and install Azure Storage Explorer from Codeplex at http://azurestorageexplorer.codeplex.com/

1. Open Azure Storage Explorer from Start | All Programs | Neudesic | Azure Storage Explorer.

Page 16

Page 17: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 15Azure Storage Explorer

2. Click Add Account.

3. In the Add Storage Account dialog enter your Storage account name, and your Storage account key. Also check the Use Https checkbox. Click Add Storage Account.

Figure 16Add Storage Account Dialog

Page 17

Page 18: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

4. If a warning dialog appears, Click OK to continue.

Note: The first time you connect to your Storage Account, the Azure Storage Explorer will scan your blobs containers to verify if they are using an old format. The program will convert the blob containers to use current Azure standards.

5. Click the New button under the Container pane.

Figure 17Creating a new container

6. In the New Container dialog, enter mydacexports as your Container Name. Click Create Container button. The new container will be displayed in the list on the left of the application.

Page 18

Page 19: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 18New Container Dialog

Task 3 – Exporting a Data-Tier Application File from SQL Azure

In this task, you will export a Data-Tier Application file from the Azure Management Portal. This file will be uploaded to your Azure Storage Container created in the previous task.

1. Open Internet Explorer and navigate to the Windows Azure Platform portal at https://windows.azure.com.

2. Log in to your Windows Live account.

Figure 19

Page 19

Page 20: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Logging in to the Azure Services Portal

3. Click on the Database button and select the server where you deployed the database from Exercise 1.

4. Now, you will export a .bacpac file with the definition schema from your database and data, if present. Select your database from the list (the one you created in Exercise 1). On the Ribbon, click Export.

Figure 20Click the Export button

Note: The .dacpac file format specifies the format of XML parts in a data-tier application (DAC) package (a .dacpac file) by using XML schema definitions. While the .bacpac file extends the DACPAC format to include a metadata file and JavaScript Object Notation (JSON)-encoded table data, in addition to the standard .dacpac file contents. For more information refer to msdn.

5. In the Export Database to Storage Account dialog, enter your Server login and password. In the New Blob URL textbox, enter your Blob storage container URL adding a filename for the .bacpac file (e.g. https://mydacstorage.blob.core.windows.net/mydacexports/booksinventory.bacpac). Click Finish.

Page 20

Page 21: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 21Export Database to Storage Account dialog

6. As this is an asynchronous process, it can take time to upload the .bacpac file into your storage container. If you are using the database from Exercise 1, the process should take a couple of minutes. A dialog will show this information along with a Request Id, just in case you want to verify the status of the request. In the dialog, click Close.

Page 21

Page 22: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 22Export Result dialog

7. Go back to the Azure Storage Explorer. If you close it, open Azure Storage Explorer from Start | All Programs | Neudesic | Azure Storage Explorer. Make sure that your storage account is selected in the drop-down list.

8. From the Containers list, select mydacexports and click the Refresh button. The exported file will be listed in the blobs plane.

Page 22

Page 23: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 23Refreshing the blobs in your Blob Container

9. Select the .bacpac file and click the Download button.

Figure 24Downloading a blob file

10. Select a location for the file. You will use it in the next task.

Task 4 – Upgrading a DAC Package

Page 23

Page 24: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

In this task, you will import the bacpac file you exported in the previous task into SSDT. You will apply some changes to the database schema and compare the changes with your database in SQL Azure.

1. Open SSDT. To do this, in Start | All Programs, click the Microsoft SQL Server Developer Tools.

2. From the File menu, choose New and then Project.

3. In the New Project dialog, select SQL Server in the Installed Templates list. Choose the SQL Server Database Project template, set the Name of the project to BooksInventory, set the location to \Source\Ex02-UpdatingDACApp, change the solution name to Begin, and ensure that Create directory for solution is checked. Click OK to create the project.

Figure 25Create SQL Server Database Project

4. In the Solution Explorer, right-click the BooksInventory project, select Import, and click on Import Data-tier Application.

Figure 26

Page 24

Page 25: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Selecting Import Data-tier Application menu option

5. Click Next in the Import Data-tier Application Wizard Welcome page.

6. Select the Import from a data-tier application package option. Click Browse and select the file you exported in the previous task. Take into account that you must change the filter in the dialog to show All Files. This is because the file has a .bacpac extension instead of .dacpac. Check the Import server selection policy, and select None from the Folder Structure drop-down list. Click Next.

Note: The Folder Structure drop-down allows you to select the way that the Wizard generates folder to organize the imported scripts. As this is a trivial example, you do not need to generate a particular folder structure.

Figure 27Specifying Import Options

7. The import procedure starts and logs any failure or warnings that might occur during the process. Click Finish to exit the wizard.

Page 25

Page 26: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 28Importing Objects

You will end up with a solution structure like the following

Figure 29Imported Objects in Solution Explorer

8. Add a new table. To do this, right click in the BooksInventory project node, select Add and click Table.

Page 26

Page 27: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 30Add Table

9. In the Add New Item dialog, make sure the Table template is selected and set the name to Genders. Click Add to create the table script.

Figure 31Creating the Genders Table

10. In the Solution Explorer, double-click the Genders table script we created in the previous step.

Page 27

Page 28: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

11. In the Design tab within the Table Designer, add the following fields to the Genders table:

Name Data Type Allow Nulls? Is Primary Key?

Id Int No Yes

Description

nvarchar(50) No No

12. Select the <unnamed> key from the right panel and press F4. The Properties panel will appear.

13. Set the Is Clustered property value to False.

14. Press Ctrl + S to apply changes.

15. In the Solution Explorer, double-click the Authors table script.

16. In the Table Designer, add a new field named GenderId as int.

17. Add a Foreign Key to the Genders table. To do this, in the Table Designer, right-click the Foreign Keys node at the right pane and select Add New Foreign Key. Set its name to FK_Authors_Genders.

Figure 32Adding the Genders Foreign Key

18. To associate your Foreign Key to the Primary Key located in the Genders table, switch to the T-SQL tab and replace the CONSTRAINT line with name [FK_Authors_Genders] with the following highlighted code.

T-SQL

CREATE TABLE [dbo].[Authors] ( [Id] INT NOT NULL, [FirstName] VARCHAR (50) COLLATE Latin1_General_CI_AS NOT NULL, [LastName] VARCHAR (50) COLLATE Latin1_General_CI_AS NULL, [GenderId] INT NULL,

Page 28

Page 29: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

CONSTRAINT [PK__Authors__42d35aa04fc8def8a5e4] PRIMARY KEY CLUSTERED ([Id]) WITH (IGNORE_DUP_KEY = OFF, ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF), CONSTRAINT [FK_Authors_Genders] FOREIGN KEY ([GenderId]) REFERENCES [Genders]([Id]))GO

19. You will update the project’s Target Platform and the Output Type. In Solution Explorer, right-click the BooksInventory project node, select Properties.

20. In the Project Settings tab, update the Target Platform to SQL Azure and make sure Data-tier Application within Output Types is checked.

Figure 33Updating SQL Server Database Project

21. Press Ctrl + S to apply changes.

Page 29

Page 30: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

22. Press CTRL+SHIFT+B to build the Solution. The Error List pane will appear showing a warning related to the new Genders table. This occurs because SSDT is validating the table schema against the target platform and detects statements which are incompatible in SQL Azure. This is useful to detect incompatibility issues between different platforms. In this case, the Genders table uses a nonclustered index, which is not supported by SQL Azure.

Figure 34Statement Options not supported in SQL Azure

23. Now, you will fix these statements. Double-click the Genders table script in the Solution Explorer and remove the NONCLUSTERED statement. Press CTRL+S to save the file.

24. Also, open the Authors and Books tables and remove the error marked statements. These are ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON and PAD_INDEX = OFF.

Task 5 – Deploying the Upgraded DAC Package

In this task, you will publish the upgraded DAC package.

1. You will change the DAC Package version number. Right-click the BooksInventory project node and select Properties.

2. In the Project Settings tab, click the DAC Properties button.

Figure 35

Page 30

Page 31: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Change DAC Properties

3. In the properties dialog, change the Version Number to 1.0.0.1 and the Description to “This is the BooksInventory Data-tier application”. Click OK.

Figure 36Changing the DAC Version Number and Description

4. Press CTRL+S to save the settings.

5. Now, you will publish the upgraded package to SQL Azure. Right-click the BooksInventory project node and select Publish.

Page 31

Page 32: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 37Publishing a DAC Package

6. Complete the Publish DAC dialog with your connection string and click Publish.

Figure 38Publish the Upgraded DAC

7. The SSDT will start uploading the scripts into SQL Azure, this could take a while to process. You will see the upgrading process in the Output pane.

Figure 39Output panel showing the upgrading process

Page 32

Page 33: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Verification

In this task you will connect to the SQL Azure Server to verify that the DAC and associated database were correctly upgraded. To do this, you will use the SQL Server Explorer that SSDT provides.

1. In the View menu, select Server Explorer.

2. If your SQL Azure server is not already added, in the Server Explorer pane, click Add SQL Server. It will prompt a Connect to Server dialog. Complete it with your Server Name and Credentials and click Connect.

Figure 40Connecting to SQL Azure

3. In the Server Explorer pane expand the SQL Server node. Locate your SQL Azure Server and expand Databases folder. Locate the BooksInventory database we created in the previous task.

4. Expand Tables folder within BooksInventory database and verify that there is a new table named Genders, and that the Authors table has a new column as foreign key named GenderId.

Page 33

Page 34: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 41DAC Upgrade Verification

5. Check if the metadata was updated correctly. To do this, in the Server Explorer, expand Management folder within your SQL Server node.

6. Expand Data-tier Applications node and select BooksInventory node.

Figure 42DAC Metadata

7. Right-click the BooksInventory DAC and select Properties. Check that the current version and description of BooksInventory values are the one you set in Task 4 of this exercise.

Page 34

Page 35: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 43DAC Metadata Upgrade Verification

Summary

In this Lab you learned how to create a new SQL Server Database Project using SSDT and to deploy it to SQL Azure. Also you learned how to export a DAC definition file using the Import/Export Service from the Azure Management Portal, and how to upgrade it in SSDT to finally publishing back the new changes.

Appendix A: Creating a SQL Azure Server

In this appendix you will learn how to connect to your SQL Azure account and create a database server, add a new user and then reconnect to SQL Azure so that you can begin working with your new server.

Task 1 – Retrieving your SQL Azure Server Name

In this exercise, you will log into the Windows Azure Management Portal to create a new SQL Azure server to your account.

1. Open Internet Explorer and navigate to the Windows Azure Platform portal at https://windows.azure.com.

2. Log in to your Windows Live account.

Page 35

Page 36: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 44Logging into the Azure Services Portal

3. At the Windows Azure Platform portal home page, click New Database Server on the ribbon.

Figure 45Creating a new SQL Azure database server

Page 36

Page 37: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

4. Select your subscription on the left pane. Click Create on the Server ribbon.

Figure 46Creating a new SQL Azure database server

5. Select a region from the Region drop down list, and then click Next. The location determines which datacenter the database will reside in.

Page 37

Page 38: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 47Choosing region

6. Enter an administrator account name and password and click Next.

Page 38

Page 39: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 48Entering administrator login and password

Note: An administrator account is a master account used to manage the new server. You should avoid using this account in connection strings where the username and password may be exposed.

The password policy requires that the password follow certain rules.

Page 39

Page 40: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

7. Click Finish to create the new server. You will configure firewall rules later on this exercise.

Figure 49Firewall rules dialog

8. Finally, the new server information, including Fully Qualified Server Name, is shown.

Page 40

Page 41: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 50SQL Azure projects list

Note: The fully qualified domain name of the server uses the following format:

<ServerName>.database.windows.net

where <ServerName> identifies the server, for example, a9ixtp7pux.database.windows.net.

9. Expand the subscription node located on the left pane and click on the server name you have created. The Server Information page allows you to perform basic administration of the database server.

Figure 51SQL Azure server information page

Page 41

Page 42: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

10. The Firewall Rules allows you to specify a list of IP addresses that can access your SQL Azure Server. The firewall will deny all connections by default, so be sure to configure your allow list so that existing clients can connect to the server.

Note: Make sure you added the necessary Firewall Rules to allow you access to the SQL Azure Server using Management Studio. Also add the Microsoft Services rule (IP Address range “0.0.0.0” to “0.0.0.0”)

Figure 52Configuring the firewall settings for SQL Azure

Note: Changes to your firewall settings can take some time to become effective.

You now have a database server created and ready for the next steps in this lab. This database can be reached from anywhere in the world.

Appendix B: Creating a Storage Account

Page 42

Page 43: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

In this appendix you will learn how to create a Windows Azure Storage Account, to do this you will need a Windows Azure account.

For a description of the provisioning process, see Provisioning Windows Azure.

Task 1 – Creating a Storage Account

In this task, you create a new Windows Azure storage account to allow your applications to persist their data.

1. Navigate to http://windows.azure.com using a Web browser and sign in using the Windows Live ID associated with your Windows Azure account.

Figure 53Signing in to the Windows Azure Platform Management Portal

2. First, you create the storage account that the application will use to store its data. In the Windows Azure ribbon, click New Storage Account.

Page 43

Page 44: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 54Creating a new storage account

3. In the Create a New Storage Account dialog, pick your subscription in the drop down list labeled Choose a subscription.

Figure 55Choosing a subscription to host the storage account

4. In the textbox labeled Enter a URL, enter the name for your storage account, for example, <yourname>guestbook, where <yourname> is a unique name. Windows Azure uses this value to generate the endpoint URLs for the storage account services.

Page 44

Page 45: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 56Choosing the URL of the new storage account

Note: The portal ensures that the name is valid by verifying that the name complies with the naming rules and is currently available. A validation error will be shown if you enter a name that does not satisfy the rules.

5. Select the option labeled Create or choose an affinity group and then pick Create a new affinity group from the drop down list.

Figure 57Creating a new affinity group

Note: The reason that you are creating a new affinity group is to deploy both the hosted service and storage account to the same location, thus ensuring high bandwidth and low latency between the application and the data it depends on.

6. In the Create a New Affinity Group dialog, enter an Affinity Group Name, select its Location in the drop down list, and then click OK.

Page 45

Page 46: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 58Creating a new affinity group

Page 46

Page 47: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

7. Back in the Create a New Storage Account dialog, click OK to register your new storage account. Wait until the account provisioning process completes and updates the Storage Accounts tree view. Notice that the Properties pane shows the URL assigned to each service in the storage account. Record the public storage account name—this is the first segment of the URL assigned to your endpoints.

Figure 59Storage account successfully created

8. To get the Storage Access Keys, click the View button next to Primary access key in the Properties pane. In the View Storage Access Keys dialog, click Copy to Clipboard next to the Primary Access Key. You will use this value to configure your applications.

Page 47

Page 48: SQL Azure Data-tier Applicationsaz12722.vo.msecnd.net/.../labs/sqlazuredac1-0/Lab.docx · Web viewIn this lab, you will learn how to use Data-tier Applications to deploy and upgrade

Figure 60Retrieving the storage access keys

Note: The Primary Access Key and Secondary Access Key both provide a shared secret that you can use to access storage. The secondary key gives the same access as the primary key and is used for backup purposes. You can regenerate each key independently in case either one is compromised.

Page 48