sharepoint 2010 and windows azure: getting...

27
Hands-On Lab SharePoint 2010 & Azure: Getting Started Lab version: 1.0.0 Last updated: 7/10/2022

Upload: others

Post on 25-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Hands-On LabSharePoint 2010 & Azure: Getting Started

Lab version: 1.0.0

Last updated: 5/24/2023

Page 2: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

CONTENTS

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

EXERCISE 1: CREATING A NEW DATABASE IN SQL AZURE..............................................................5Task 1 – Connecting to SQL Azure and Creating a Database................................................................5

EXERCISE 2: CREATING AND A NEW TABLE IN SQL AZURE AND POPULATE WITH DATA...........8Task 1 – Creating a Table.....................................................................................................................8

Task 2 – Populating the StoreInformation Table with Data.................................................................8

EXERCISE 3: CONSUMING SQL AZURE DATA IN SHAREPOINT 2010 USING BCS...........................9Task 1 – Creating an Application ID in Secure Store Service................................................................9

Task 2 – Creating an External Content Type that Connects to SQL Azure..........................................10

EXERCISE 4: CREATING A VISUAL WEB PART THAT IS INTEGRATED WITH SQL AZURE...........17Task 1 – Creating a new Visual Web Part that connects to the StoreInformation SQL Azure database...........................................................................................................................................................17

APPENDIX................................................................................................................................................ 20Provisioning a SQL Azure Account.....................................................................................................20

Page 3: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Overview

This lab introduces some of the ways in which you can integrate SharePoint 2010 and Azure. While there are many ways, this lab focuses on SQL Azure as a hosted data source in the cloud and then integrates that data source with an external list and with a visual web part.

Objectives

The goals of this lab are:

To understand how to create a SQL Azure table

To use SQL Azure with an external list

To use SQL Azure with a visual web part.

System Requirements

You must have the following items to complete this lab:

Microsoft Visual Studio 2010.

ASP.NET AJAX 4.0 Preview 2.

An Azure developer account and key.

SQL Server 2008 R2

Azure SDK and Tools

To provision an Azure account and obtain your developer key, go to the following site and click Get Started: http://www.azure.com.

Note: You can also see the Appendix for introductory information on how to get started with SQL Azure.

After you’ve got an Azure account provisioned and have your developer key, you are now ready to begin the HOL.

Exercises

In this HOL, you will 1) create a new database called Customers and table called Store Information in your SQL Azure Customer database, 2) add some data to the SQL Azure (Store Information) table, 3) create an external list that loads the SQL Azure data using BCS, and 4) consume the SQL Azure data in a visual web part.

Page 4: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Estimated time to complete this lab: 60 minutes.

Starting Materials

This Hands-On Lab includes the following starting materials.

Visual Studio solutions. The lab provides the following Visual Studio solutions that you can use as starting point for the exercises.

◦ SQLAzureWebPart\SQLAzureWebPart.sln

Page 5: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Exercise 1: Creating a new Database in SQL Azure

Task 1 – Connecting to SQL Azure and Creating a Database

1. Open SQL Server Management Studio. Start > All Programs > SQL Server 2008 R2 November CTP > SQL Server Management Studio. You will be presented with a logon dialog.

Figure 1SQL Server Management Studio Default Connection Dialog

2. Enter your login information ensuring that you selected SQL Server Authentication. SQL Azure currently only supports SQL Server Authentication. Click on the Options tab, and specify the database to connect to as master. Click Connect.

Page 6: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Note: Please replace server name with your assigned server, i.e. REPLACE_SERVER_NAME.database.windows.net

Figure 2Connecting to SQL Azure

Figure 3Connect to master database

Page 7: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

3. You should now see in your Object Explorer the structure of your database. Notice that your SQL Azure database is no different to an on premise relational database.

Figure 4The Object Explorer

4. Click the New Query button. This will open a similar dialog requesting logon information.

Figure 5Creating a New Query Window

5. You now have a query window with an active connection to your account.You will now create a new Database. One of the good things about SQL Azure is that it takes care of much of the management of our database for us including how to manage the underlying data files. This means that our Create Database statement can be very simple. Type Create Database Customers and click Execute

Figure 6Creating a New Database

Note: You can select which SQL Azure Database edition (Web or Business) is created during the database provisioning process. This is surfaced both in the SQL Azure Portal and in the T-

Page 8: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

SQL Create Database statement. For example, to create a Business Edition database the T-SQL command would be as follows: CREATE DATABASE HolTestDB (MAXSIZE = 10GB). Once a database has been created, the database size will not be able to be changed.

Exercise 2: Creating and a new Table in SQL Azure and Populate with Data

Task 1 – Creating a Table

1. If you closed SQL Server Management Studio, open it again from Start > All Programs > SQL Server 2008 R2 November CTP > SQL Server Management Studio.

2. Connect to the Customers database using your SQL Azure SQL Server login.

3. Now you will add a table called StoreInformation to the Customers database. Execute the following query in a New Query window:

T-SQL

CREATE TABLE [StoreInformation]( [StoreID] [int] IDENTITY(1,1)NOT NULL PRIMARY KEY CLUSTERED, [Title] [nvarchar](8)NULL, [StoreName] [nvarchar](50)NOT NULL, [StoreAddress] [nvarchar](50)NOT NULL, [StorePhone] [nvarchar](50)NOT NULL, [Latitude] [nvarchar](50)NOT NULL, [Longitude] [nvarchar](50)NOT NULL, [Hours] [nvarchar](8)NOT NULL, [Timestamp] [timestamp] NOT NULL)

Task 2 – Populating the StoreInformation Table with Data

1. Execute a series of queries similar to the following to add a set of rows to the new Customer table:

T-SQL

INSERT INTO [StoreInformation]([Title],[StoreName],[StoreAddress],[StorePhone],[Latitude],[Longitude],[Hours]) VALUES

Page 9: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

('30','Canyon Sports','Terrance Mall, Denver, CO USA','320-555-0188','38.627499999','102.221','12')

2. Now let’s query the data back out of the StoreInformation table to display the data you just entered.

T-SQL

SELECT * FROM Customers.dbo.StoreInformation

The result of the query should look something similar to the following:

Figure 7Creating the StoreInformation Database

Exercise 3: Consuming SQL Azure Data in SharePoint 2010 using BCS

Because SQL Azure uses a separate set of credentials than your Windows (and SharePoint) credentials, you can use Secure Store Service to manage the connection to the remote SQL Azure database.

Task 1 – Creating an Application ID in Secure Store Service

1. Open SharePoint Central Administration. Start > All Programs > Microsoft SharePoint 2010 Products > SharePoint Central Administration.

2. Navigate to the Secure Store Service and click a Secure Store Service instance. Manage Service Applications > Secure Store Service.

Page 10: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Figure 8Secure Store Service

Note: If there is no service instance, you may have to create one. To do this click the New button and then select Secure Store Service.

3. Create a new Application ID. Click New and then complete the first page of the wizard. You’ll need to fill in a Target Application ID (e.g. SQLAzureAppID), Display Name (e.g. Azure App ID), Contact Email ([email protected]), select a Target Application Type (you can leave it on Individual for this exercise), and then select a Page URL (leave the default selection Use Default Page selected). Click Next.

4. Configure the Application ID fields as per Figure 9. Click Next when done.

Figure 9New Application ID

5. Add administrators to the Application ID and click OK to complete the wizard. You have now created an Application ID.

Task 2 – Creating an External Content Type that Connects to SQL Azure

1. Open SharePoint Designer 2010. Open your SharePoint site and then click Site Actions > Edit in SharePoint Designer.

2. Create a new External Content Type. External Content Types > External Content Type.

3. Click the Name and Display Name fields to add a name (e.g. MyAzureECT) and leave the Namespace, Version and Identifiers with their defaults. Select the Contact option from the Office Item Type and leave the Offline Sync for external List as Enabled. To configure the external content type to load your SQL Azure data, click the Click here to discover… link.

Page 11: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Figure 10New External Content Type

4. Click Add Connection to add a connection to your SQL Azure instance. Select the SQL Server option and click OK.

Figure 11Adding a New Connection to the External Content Type

5. Add your SQL Azure database name in the Database Server field, the database name in the Database Name field, and add an optional Name parameter in the Name (optional) field. Select Connect with Impersonated Custom Identity and add the Application ID name you created earlier in the HOL.

Page 12: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Figure 12Completing the External Content Type Connection using Impersonated Identity

6. Add your SQL Azure database name in the Database Server field, the database name in the Database Name field, and add an optional Name parameter in the Name (optional) field. Select Connect with Impersonated Custom Identity and add the Application ID name you created earlier in the HOL. Click OK.

7. After it’s connected, the connection will appear in the Data Source Explorer.

Page 13: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Figure 13New SQL Azure Connection in Data Source Explorer

8. Right-click the new connection and select Create All Operations. This will create a full CRUD-enabled external content type.

Figure 14Creating All Operations for the External Content Type

9. When prompted with the first page of the Operations wizard, click Next. In the Parameters Configuration view, map the StoreName to the Last Name Office Property. Leave the other

Page 14: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

defaults and click Next and then click Finish (don’t add any filters as there is not enough data).

Figure 15Operations Wizard

10. Save the external content type. Click the Save icon in the upper-left hand part of the window.

Figure 16Final External Content Type

Page 15: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

11. Create a new external list using the new external content type. Click Create Lists and Forms and provide a List Name and click OK. Leave the other default options.

Figure 17Creating External List

12. Navigate to the SharePoint list, and you’ll likely find that you do not yet have any permissions associated with the list.

Figure 18Access Denied in External List

Page 16: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

13. Add permissions to the external list. SharePoint Central Administration > Manage Service Applications > Business Data Connectivity Services. Click the new external content type you created and then select Set Object Permissions. Type the user’s alias into the Add field and then click Add. Associate the permissions you want with the newly added user.

Figure 19Adding User to Permissions List for External List

When you return to the list, you will now find that the list can display without any security error.

Figure 20External List

Page 17: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Exercise 4: Creating a Visual Web Part that is Integrated with SQL Azure

Task 1 – Creating a new Visual Web Part that connects to the StoreInformation SQL Azure database

1. Open Visual Studio 2010. Start > All Programs > Microsoft Visual Studio 2010 > Visual Studio 2010. Run as Administrator.

2. Create a new Visual Web Part project. File > New Project > SharePoint > Empty SharePoint Project > Provide a Name > Deploy as Farm Solution > Finish.

3. Right-click the newly created project and add a new visual web part. Add > New Item > Visual Web Part. Provide a name for the web part (e.g. SQLAzureVisualWebPart).

4. Right-click the .ascx file (e.g. SQLAzureVisualWebPart.ascx) and select View Designer. Click Source.

5. Add the bolded code below to the ascx file. Double-click the linkbutton to add an event to the code behind.

ASP.NET

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %><%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %><%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SQLAzureVisualWebPartUserControl.ascx.cs" Inherits="SQLAzureWebPart.SQLAzureVisualWebPart.SQLAzureVisualWebPartUserControl" %><style type="text/css">

Page 18: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

.style2 { font-family: Calibri; font-size: small; color: #000066; }</style><table><tr><td> <span class="style2"><strong>Store Information</strong></span></td></tr><tr><td> <asp:GridView ID="datagrdStoreData" runat="server" BackColor="White" style="font-family: Calibri; font-size: small"> <AlternatingRowStyle BackColor="#99CCFF" ForeColor="Black" /> <HeaderStyle BackColor="#0099CC" ForeColor="White" /> </asp:GridView></td></tr><tr><td> <asp:LinkButton ID="lnkbtnGetStoreInformation" runat="server" style="font-family: Calibri; font-size: small" onclick="lnkbtnGetStoreInformation_Click">Get Store Data</asp:LinkButton></td></tr></table>

6. Add the following bolded code to the code-behind. This will use a SQL Data Connection string to load and bind the data to a data-grid.

C#

using System;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Data;using System.Data.SqlClient;

namespace SQLAzureWebPart.SQLAzureVisualWebPart{ public partial class SQLAzureVisualWebPartUserControl : UserControl {

Page 19: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

string queryString = "SELECT * from Customers.dbo.StoreInformation;"; DataSet azureDataset = new DataSet();

protected void Page_Load(object sender, EventArgs e) { }

protected void lnkbtnGetStoreInformation_Click(object sender, EventArgs e) { string connectionString = "Server=tcp:SERVER.database.windows.net;Database=Customers;User ID=USER@SERVER;Password=PASSWORD;Trusted_Connection=False;Encrypt=True;";

using (SqlConnection connection = new SqlConnection(connectionString)) { SqlDataAdapter adaptor = new SqlDataAdapter(); adaptor.SelectCommand = new SqlCommand(queryString, connection); adaptor.Fill(azureDataset); datagrdStoreData.DataSource = azureDataset; datagrdStoreData.DataBind(); }

} }}

7. Amend the Title and Description properties of the .webpart file, as is bolded below.

XML

<?xml version="1.0" encoding="utf-8"?><webParts> <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"> <metaData> <type name="SQLAzureWebPart.SQLAzureVisualWebPart.SQLAzureVisualWebPart, $SharePoint.Project.AssemblyFullName$" /> <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage> </metaData> <data>

Page 20: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

<properties> <property name="Title" type="string">SQL Azure Visual Web Part</property> <property name="Description" type="string">A visual web part that loads SQL Azure data using a SQL Connection string.</property> </properties> </data> </webPart></webParts>

8. Deploy and test the web part. Right-click the project > Deploy.

9. Navigate to your SharePoint site and add the new web part. Site Actions > Edit Page > Insert > Web Part > Custom. Select your new visual web part and click Add.

10.When the visual web part loads, click the Get Store Data linkbutton to retrieve the data from SQL Azure.

Figure 21SQL Azure Visual Web Part

Appendix

Page 21: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

If you’ve not provisioned a SQL Azure account before, to follow is some information (taken from the Channel 9 Azure Training Kit) that provides some introductory information on how to create your account. You can download the full Azure training kit from the following location: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=413e88f8-5966-4a83-b309-53b7b77edf78&displaylang=en .

Provisioning a SQL Azure Account

1. Go to the website https://sql.azure.com

2. Login to your Windows Live account.

Figure 1Logging into the Azure Services Portal

3. Type in your invitation code and then click Submit.

Page 22: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Figure 2Entering a SQL Azure Token

4. Read the terms of use then click then Accept button.

Figure 3Accepting the Terms of Use

5. Fill in an admin account name, password and region, and then click Create Server. The Location determines which datacenter the database will reside in.

Page 23: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Figure 4Create a server and set administrator passwords.

Note: An admin account is a master account used for administering the new server. This should not be used in connection strings where the username and password may be exposed.

The password policy requires that this password contain at least one number, one character and one letter and one symbol. In addition, the password cannot be less than six characters nor contain three consecutive characters from the username.

6. The virtual server should now be created and a list showing your projects should be displayed. To view the databases on the virtual server click the project.

Figure 5SQL Azure Projects List

7. The Server Administration screen allows basic administration of the database server and allows a quick way of viewing the available connection strings.

Page 24: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Figure 6SQL Azure Server Management .Your server fully qualified domain name will take the following format: <ServerName>.database.windows.net.

8. The new firewall features allows a customer to specify an allow list of IP address that can access their SQL Azure Server. Your firewall will deny all connections by default, so be sure to configure your allow list so that existing clients can continue to connect.

Page 25: SharePoint 2010 and Windows Azure: Getting Startedaz12722.vo.msecnd.net/.../labs/introspazure1-0/Lab.docx · Web viewThis lab introduces some of the ways in which you can integrate

Figure 7SQL Azure Server Management – Firewall Settings

Note: The application of your firewall settings can take a few moments

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