Professional Documents
Culture Documents
SQL Azure is the SQL Server teams name for a set of highly scalable cloud services based on a customized version of SQL Server 2008 and related services hosted in Microsoft data centers. SQL Azure is intended to provide the capabilities of an enterprise-grade data center without the capital cost of its physical facilities or the operating expenses for its management or maintenance, as well as server and database license fees. SQL Azure provides high availability by replicating a total of three redundant copies of your data to separate physical servers. SQL Azure achieves scalability while maintaining transactional consistency by partitioning data into individual 10GB or smaller databases. When this chapter was updated in January 2010, only the rst of these services SQL Azure Database (SADB) v1, a scalable and available relational database had been released as a commercial product. Ultimately, SQL Azure will consist of the following services: SQL Azure Database to provide core SQL Server database capabilities (released during PDC 2009). Azure Data Sync to enable synchronizing cloud and on-premises SQL Server and SQL Azure databases with the Microsoft Sync Framework. Chapter 13 describes Azure Data Sync. Business Intelligence (BI) and Reporting Services (RS) with no current CTP or release timetable.
This chapter concentrates on creating a SQL Azure account, getting connected to an SADB v1 server, and creating user databases with SQL Server Management Studio (SSMS) 2008 R2 November 2009 CTP [Express] and the sqlcmd utility. This chapter was written after SADB released to the Web (RTW) as a commercial product with service fees. When you connect to the commercial version, the credit card you specify when creating your account will be charged US$9.99 per month for a database size up to 1GB (Web Edition) and US$99.99 per month for up to 10GB of space (Business Edition), plus US$0.10 per GB of data ingress and US$0.15 per GB of data egress.
For more background on the MIX08 SSDS announcement and early reaction to SSDS in the computer trade press, see the SQL Server Data Services to Deliver Entities from the Cloud post of March 7, 2008, to the OakLeaf blog (http://bit.ly/SJydJ, http://oakleafblog.blogspot.com/2008/03/ sql-server-data-services-to-deliver.html) and Spelunking SQL Server Data Services (http://bit.ly/gS7RR, http://oakleafblog.blogspot.com/2008/03/spelunking-sqlserver-data-services.html). The initial SSDS architects chose the Entity-Attribute-Value (EAV) data model implemented by a hierarchical set of Authority, Container, and Entity (ACE) objects, rather than the traditional relational data model because EAV databases could scale out to extreme sizes, typied by Googles BigTable and Yahoo!s Hadoop examples. The problem with this approach was the difculty that potential customers encountered when attempting to distinguish SSDS tables from the similar EAV tables offered by Azure Data Services. Further, the Azure marketing team was strongly promoting the benets of leveraging developers experience with .NET programming and Visual Studio to ease the burden of migrating conventional ASP.NET applications and .NET-based services from on-premises data centers to those in the cloud. Developers and their management were more interested in leveraging their relational database design and Transact-SQL (T-SQL) query skills than the potential for increased scalability. Architects and developers also had misgivings about the eventual consistency
The Transact-SQL Reference chapter is especially useful because it contains lists of supported, partially supported, and unsupported T-SQL reserved words. The Windows Azure team released the Windows Azure Platform Training KitDecember [2009] Update for downloading on December 23, 2009, at http://bit.ly/3Nwdbn, http://www.microsoft.com/ downloads/details.aspx?FamilyID=413E88F8-5966-4A83-B309-53B7B77EDF78&displaylang=en . The kit offers the following SQL Azure Databasespecic elements in .pptx, .docx, or .htm format: Presentations What is SQL Azure? Introduction to SQL Azure Building Applications using SQL Azure Scaling Out with SQL Azure
Demonstrations Preparing Your SQL Azure Account Connecting to SQL Azure Managing Logins and Security in SQL Azure Creating Objects in SQL Azure Migrating a Database Schema to SQL Azure Moving Data Into and Out Of SQL Azure using SSIS Building a Simple SQL Azure App Scaling Out SQL Azure with Database Sharding
Hands On Labs Migrating Applications to Windows Azure Introduction to SQL Azure Migrating Databases to SQL Azure
Demonstrations and Hands-On Labs require a sample database, so you must have a commercial SQL Azure account in which to create the database. You can nd the SQL Azure Getting Started forum at http://bit.ly/ARCwN, http://social.msdn. microsoft.com/forums/en-US/ssdsgetstarted/threads/.
SQL Azure Team blog (http://bit.ly/61OS6H, http://blogs.msdn.com/ssds/archive/2010/ 01/04/9943474.aspx) Windows Azure Platform AppFabric Team Blog (http://bit.ly/6a9xuS, http://blogs.msdn.
com/netservices/archive/2010/01/04/announcing-windows-azure-platform-commercialoffer-availability-and-updated-appfabric-pricing.aspx)
The following procedure will create new commercial Windows Azure, SADB, and Azure AppFabric (formerly .NET Services) accounts with the Windows Live ID, or if you use the Live ID account with which you created free CTP accounts, it will upgrade the CTP accounts and their projects to commercial status. The procedure and screen captures that follow are based on the OakLeaf Blogs How to Create and Activate a New Windows Azure and SQL Azure Account or Upgrade an Existing Account post of 1/5/2010 (http://bit.ly/4riEfv, http://oakleafblog.blogspot.com/2010/01/how-to-create-andactivate-introductory.html).
1.
Log in to the Windows Azure Development Portals SQL Azure Project Viewer page (http://bit.ly/4riEfv, https://sql.azure.com/ProjectViewer.aspx) with your Windows Live ID, and click the Billing link at its upper-right corner (see Figure 12-1) to open the Microsoft Online Services Customer Portal (MOCP) landing page.
Figure 12-1: The Billing link of the SQL Azure Project Viewer page. Alternatively, browse directly to the MOCP landing page (http://bit.ly/nPKPg, https://mocp.microsoftonline.com/site/default.aspx) and click Continue to open the Getting Started page (see Figure 12-2).
2. 3.
If you arent signed in, click the Sign In link, and sign in with your Windows Live ID. If youre creating a new account, you must complete Contact Information, Company Information, and Service Usage Address forms. Click the Services tab and click the Windows Azure Platform link (see Figure 12-3).
Figure 12-2: The Microsoft Online Services Customer Portals Getting Started page.
Figure 12-3: The Services tab for Applying the Windows Azure Platform lter.
4. 5.
Click any Rate Plan link to open a Pricing Info page (see Figure 12-4). If you dont qualify for a Partner Network discount or MSDN Premium special offer, click the Buy button for one of the three free or paid accounts, complete, and skip to step 8. (The Windows Azure Platform Introductory Special offers very limited compute hours and small storage quotas at no charge. The two paid plans require agreement to a six-month subscription duration.)
6.
If you have an MSDN Premium subscription, click the Special Offers for MSDN Windows Azure Platform Benets link to open the Windows Azure Platform Benets for MSDN Subscribers page (see Figure 12-5).
Figure 12-5: This page explains temporary discounts offered to MSDN subscribers.
7. 8.
Scroll to the grid at the bottom of the page to learn details of the introductory benet plan for the rst eight months and three levels of ongoing plans when the introductory plan expires. Click the My Account link to open the My Account page (see Figure 12-6).
Figure 12-6: The My Account page conrms your MSDN subscription and presents a Windows Azure Platform link.
9.
Click the Windows Azure Platform link to open the MOCP Subscriptions Shopping Cart page, which has the Windows Azure Platform MSDN subscription details added where appropriate MSDN Premium for this example (see Figure 12-7).
Figure 12-7: The Shopping Cart pages Billing Information pane indicates the MSDN benet appropriate for your subscription level.
11.
Click Checkout, provide your credit card data, if requested, and complete the transaction to open the Review and Conrm Order page (see Figure 12-8).
Figure 12-8: The Shopping Cart pane summarizes your subscription data.
12.
Click Conrm Order to open the Things I Need To Do page, and select Activate Now in the list (see Figure 12-9).
Figure 12-10: The Service Activation Summary page lets you review the activation details, including the portals that will be affected.
15.
Click Finish to complete the activation process. In a few minutes, youll receive a conrmation message at the e-mail alias of your Live ID account (see Figure 12-11). Apparently, the MOCP team didnt receive word that .NET Services was renamed Windows App Fabric at PDC 2009, as you can see in the e-mails third bullet point.
16. 17.
Click the Developers Portals SQL Azure link to display the upgraded SQL Azure project (see Figure 12-12). If youre starting a new account with a different Windows Live ID, accept the Terms of Use to open the Create Server page, type a Server Administrator username and password, retype the password, and select the Microsoft data center to provide your database(s) from the list (see Figure 12-13). The Server Administrator for the account corresponds to SQL Servers sa login. When this chapter was updated, only South Central U.S. (San Antonio, TX), North Europe (Dublin), and Southeast Asia (Singapore) data centers supported SQL Azure accounts. Support for SQL Azure by additional Microsoft data centers in the U.S. and Europe is expected in early 2010. To prevent brute force attacks from succeeding with common user names, such as SA, Admin and Root, SQL Azure prevents use of these name.
10
Figure 12-11: A message such as this one conrms your new or upgraded Windows Azure, SQL Azure, and Windows AppFabric (formerly .NET Services) accounts.
Figure 12-12: The Windows Azure Summary page has links to your new or upgraded Windows Azure, SQL Azure, and Windows AppFabric (formerly .NET Services) accounts.
18. 19.
For a new account, click Create Server to add the new SQL Azure server to the account. This may take several minutes to complete and display the My Projects page. Click the Project Name OakLeaf Azure MSDN Subscription, for this example to open the Server Administration page, which lists the CTP databases upgraded to commercial
11
Figure 12-13: Supplying Server Administrator credentials and selecting a data center for the server.
Figure 12-14: Upgrading an existing SQL Azure CTP project upgrades the original databases.
12
Figure 12-15: Marking the check box enables any Microsoft-hosted service to attempt to connect to the SQL Azure server. To enable client applications to attempt to connect via the Internet to the server, click the Add Rule button to open the Add Firewall Rule form, then type a name for the rule and the range of IP addresses to accept (see Figure 12-16). The Add Firewall Rule form includes the IP address of the calling computer for reference. However, the Internet rewall is effective only for clients that have a xed IP address. Most Internet service providers (ISPs) use the Dynamic Host Conguration Protocol (DHCP) to assign IP addresses from allocated blocks to client computers. Unless you know the range of IP addresses that your ISP can assign, you must allow all incoming addresses by specifying a range from 0.0.0.0 to 255.255.255.255. Firewall settings are cached for ve minutes, so changes might not appear immediately.
Figure 12-16: Enable client applications to attempt to connect to the SQL Azure server by specifying the allowable range of IP addresses.
13
Figure 12-17: The SQL Azure Portals Server Administration page for adding or dropping user databases. Type the user database name and click Create to close the dialog, add the user database to the server, and enable the Drop Database button when you select a user database (see Figure 12-18). Alternatively, you can create or drop a user database by opening the master database in SSMS 2008 R2 [Express] and executing a CREATE DATABASE DatabaseName or DROP DATABASE DatabaseName T-SQL command. The later Connecting to SADB Master and User Databases with SSMS 2008 R2 [Express] section describes how to connect to databases with SSMS 2008 R2 [Express]. You cant connect to SQL Azure databases with SSMS 2005 [Express], and SSMS 2008 [Express]s Object Explorer doesnt display SQL Azure objects.
14
Figure 12-18: The SQL Azure Portals Server Administration page after adding an empty Northwind user database. Clicking the Connection Strings button opens a message with ADO.NET and ODBC connection strings for the Master database that you can copy to the Clipboard:
ADO.NET Server=tcp:k8jv7gpmwb.database.windows.net;Database=master; User ID=rogerj;Password=myPassword;Trusted_Connection=False;Encrypt=True; ODBC Driver={SQL Server};Server=tcp:k8jv7gpmwb.database.windows.net;Database=master; Uid=rogerj@k8jv7gpmwb;Pwd=myPassword;Encrypt=yes;
The tcp: prex species that the connection will use SQL Servers native Tabular Data Stream (TDS) protocol over TCP port 1433. SQL Azure connections are encrypted by default; the server will terminate the connection if the client doesnt accept encryption. With a user database selected, click the Connection Strings button to open a message that contains examples of ADO.NET and ODBC connection strings for the selected user database (see Figure 12-19). Click the ADO.NET entrys Copy to Clipboard link to save the connection string for use with on-premises or Windows Azure clients.
15
Figure 12-19: Connection strings for ADO.NET and ODBC drivers for the Northwind database.
16
1. 2. 3.
Launch SSMS 2008 R2 [Express], and click SSMSs New Query toolbar button to open the Connect to Database dialog. Accept the default Database Engine Server Type; copy the ADO.NET connection string sample to the Server Name text box, trimming the entry to the server name, including the tcp: prex; and (optionally) select the Remember Password check box. Select SQL Server Authentication in the Authentication list, and type the server administrator credentials you created in the preceding section in the Login and Password text boxes (see Figure 12-21).
Figure 12-21: Specifying SADB login parameters in the standard Connect to Server dialog.
4.
SADB doesnt support the T-SQL USE command and, therefore, requires you to specify the database to which to connect. So, click the Options >> button to expand the dialog. In the Connect to Database combo box, accept the <default>, or type master for the master database or the name of an existing user database, and select the Encrypt Connection check box (see Figure 12-22). SADB connections are encrypted with Transport Level Security (TLS) by default, but marking the Encrypt Connection check box will please your organizations data security auditors.
5.
Click Connect to open the connection and click New Query to open the Query Editor pane. Verify that the database you specied in the preceding step is active by examining the highlighted status bar. Note that the toolbars Available Databases list is disabled.
To run a test query against a system view, execute a SELECT * FROM sys.all_objects command (see Figure 12-23). To conserve resource consumption, SADB automatically closes connections after ve minutes of inactivity. To reopen a closed connection click the Connect or Change Connection buttons at the extreme left of the SQL Editor toolbar.
17
Figure 12-23: The status bar identies the connections xed database name.
18
Figure 12-24: Executing a T-SQL query against the master database to retrieve rewall rules in effect. SQL Azure offers two system stored procedures to create or update and delete server rules by name: Run exec sp_set_firewall_rule NAllow Windows Azure,0.0.0.0,0.0.0.0 to create or update the named rule. Run exec sp_delete_firewall_rule NAllow Windows Azure to delete the named rule.
Figure 12-25: Retrieving your database usage history from the servers master database.
19
Description Show syntax summary Server (use complete DNS name) Server administrator name in login@servername (name only) format Server administrator password User database name (default is master) Query input (T-SQL) le path\name Query output le path\name
Figure 12-26: The Windows command prompt displaying the sqlcmd syntax summary. After connecting to SADB, executing T-SQL statements and batched queries with sqlcmd is a simple process. At the sequentially numbered #> prompt, type a valid T-SQL command, and press Enter. Type GO and press Enter to execute the preceding command(s) and reset the prompt number to 1. Type quit or exit to close the session. Figure 12-27 shows sqlcmds window after executing the SELECT name FROM sys.tables command against the Northwind database you create with SSMS and a modied version of the InstNwind.sql script in the next chapter.
20
Figure 12-27: Using sqlcmd to display a list of table names in a sample Northwind database.
Summar y
SQL Azure Database is the basic element of SQL Azure. SADB provides a highly scalable and available relational database as a public cloud computing resource running together with the Windows Azure Platform in most of Microsofts newly constructed data centers. The SADB Web Edition supports transactional-consistent databases up to 1GB in size; the Business Edition is limited to 10GB or less.
21
22