This tutorial demonstrates the process of creating a Windows Azure cloud service consuming Windows Azure SQL Database and the process of deploying the application to Windows Azure.
Last reviewed: 11/4/2011
Tutorial 1: Using Windows Azure Web Role and Windows Azure Table Service (en-US), you created a simple golfer message board application. In the application, a ASP.NET Web role provides the front-end that allows golfers to view the contents of the message
board and post new entries. Each entry contains a name and a message. When golfers post a new message, the Web role creates an entry that contains the information entered by the golfers using Windows Azure Table service. In this tutorial, you will modify the
application so that it uses SQL Database instead of the Table service.
Here is a screenshot of the application:
Note: This tutorial is not intended to show you how to choose between SQL Database and the Table service, but to show you how to use SQL Database. For information on SQL Database and Windows Azure Table service comparison, see
Windows Azure SQL Database and Windows Azure Table Service at
http://msdn.microsoft.com/en-us/magazine/gg309178.aspx, and Understanding Data Storage Offerings on the Windows Azure Platform.
Tutorial 1 is not a pre-requisite for this tutorial, however, it helps with understanding the scenario.
Note: The tutorial code has been tested on
Windows Azure SDK (October 2012).
Note: For the tutorial in PHP, see Using the Windows Azure Web Role and SQL Database with PHP.
In this tutorial, you will learn how to:
Note the following requirements before you begin this lesson:
The following diagram illustrates the development components and the runtime components involved in this tutorial:
In this lesson, you connect to your SQL Database account and create a server and a database for the Golfer Message Board application using Windows Azure Management Portal. You can also use SQL Database Management API to create SQL Database servers, databases,
and tables programmatically. For more information, see
Management REST API Reference.
In this lesson, you will go through the following procedures:
You must have a Windows Azure Platform subscription.
To create a SQL Database server and a database
New SQL Database Server
LOGIN PASSWORD CONFIRMATION
(Select a region that you want your service to reside. For better performance, choose the one that is close to you.)
ALLOW WINDOWS AZURE SERVICES TO ACCESS THE SERVER
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. To simplify the tutorial instructions, this tutorial
uses the administrator account. The default administrator username is MyAdmin, and the default password is
pass@word1. If you change the username and the password in this step, you must change them accordingly in the rest of the tutorial.
Note: The password policy requires that this password contain at least one number, one character, one letter, and one symbol. In addition, the password cannot be less than six characters nor contain three consecutive characters from the
You can use either SQL Server Management Studio or Windows Azure Management Portal to manage your SQL Database. To connect to SQL Database from SQL Server Management Studio, you must provide the fully qualified domain name of the server. In this tutorial,
you will use Windows Azure Management Portal.
Note: The SQL Server Management Studio from SQL Server 2008 R2 and SQL Server 2008 R2 Express can be used to access, configure, manage and administer SQL Database. Previous versions of SQL Server Management Studio are not supported.
SQL Database has two types of access control: firewall and SQL authentication. You must configure the SQL Database firewall settings to allow connections from your computer(s). You must also allow connections from Windows Azure, because the golfer message
board application is hosted in Windows Azure (This is done in the previous procedure). In addition to configuring the SQL Database server-side firewall, you must also configure your client-side environment to allow outbound TCP connections over TCP port 1433.
For more information on SQL Database security, see Security Guidelines for Windows Azure SQL Database.
To create a SQL Database server firewall rule
The Golfer Message Board application has one table for storing the messages.
To create a table
(use default value)
CREATE TABLE [Messages](
[MessageID] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[GolferName] [nvarchar](100) NOT NULL,
[GolferMessage] [nvarchar](1000) NOT NULL,
[Timestamp] [datetime] NOT NULL
In this step, you created a SQL Database server, a database, and a table needed by the golfer message board application.
You will modify the golfer message board application you created in tutorial 1 so that it uses SQL Database instead of the Table service for storing the messages.
Currently, the application only needs to access a single table. It is easy and straightforward to access the data using LINQ.
There are two places you need to modify the application to use SQL Database. One is listing the messages, and the other is inserting new messages to the database.
To open the Golfer Message Board application
To create message entity class
Visual C# , Data
LINQ to SQL Classes
Microsoft SQL Server
Microsoft SQL Server (SqlClient
User SQL Server Authentication
Select or enter a database name
Note: SQL Database doesn’t support unencrypted connections. If you try to request a connection via SQL Server Management Studio that is unencrypted, SQL Database signals SQL Server Management Studio to establish an encrypted connection.
To change the Encrypt setting, click Advanced from the
Add Connection dialog. For more information, see Overview of Security in Windows Azure SQL Database.
Note: The <ServerName> is the SQL Database server name you wrote down when you created the server.
Note: SQL Database supports only SQL Server Authentication. For more information, see
Security Guidelines and Limitations (Windows Azure SQL Database) at
In tutorial 1, you used a DataList control and an ObjectDataSource control to list the messages. You will replace the ObjectDataSource control with a LinqDataSource control in this tutorial.
To modify the Default.aspx page for listing the messages
Note: Click Ctrl+Alt+X to display the Toolbox. The
LinqDataSource control is listed under the Data category. The dsMessages control appears on the bottom of the page.
Note: The context object will not be listed until you compile the MessageBoard_WebRole project.
To modify the Default.aspx.cs page for inserting new messages
protected void btnSend_Click(object sender, EventArgs e)
MessageBoardDataContext context = new MessageBoardDataContext();
var newMessage = new Message
GolferName = txtName.Text,
GolferMessage = txtMessage.Text,
Timestamp = DateTime.UtcNow
txtName.Text = "";
txtMessage.Text = "";
If you don't see the code snippet, follow the instructions found in Windows Azure And SQL Database Tutorials (en-US) to copy the snippet.
To compile the MessageBoard_WebRole project
In Solution Explorer, right-click MessageBoard_WebRole, and then click
Rebuild. Make sure the project is compiled successfully.
In this step, you modified the golfer message board application to connect to SQL Database via LINQ.
You will test and deploy the application.
In this lesson, you test the application in Windows Azure computer emulator, package the application, and then deploy the application to Windows Azure.
Note: If you don’t have a Windows Azure Platform subscription, see the
Provisioning Windows Azure section of this tutorial.
To test the application in compute emulator
After the application is tested successfully in the compute emulator environment, the next step is to create the service package and then deploy the application to Windows Azure.
To generate the service package
To sign in to Windows Azure
Note: If you haven’t had a Windows Azure Platform subscription, see the
Provisioning Windows Azure section of this tutorial.
You need to create a cloud service for the Web role. If you have created a cloud service account in tutorial 1, you can skip
To create a cloud service
Note: The URL prefix must be unique.
To deploy the application to the staging environment
To test the application in the staging environment
After the application is working correctly in the staging environment, you are ready to promote it to the production environment.
To promote the application to production
Note: Some DNS services take longer to replicate the records. If you get a page not found error, you might need to try browsing to the URL again in a few minutes.
In this step, you tested and deployed the golfer message board to Windows Azure.
Congratulations! You have completed the tutorial 2.
tutorial 3 shows you another Windows Azure storage called Blob.
tutorial 2.1, which is optional, shows you how to add a data service that implements the Open Data Protocol (OData) to the project.
Jonathan Gao edited Revision 21. Comment: updating the architecture diagram
Jonathan Gao edited Revision 23. Comment: include the information on the SQL Azure Database Management API.
Glenn Gailey [MSFT] edited Revision 28. Comment: Added a link to the new 2.1 tutorial
Glenn Gailey [MSFT] edited Revision 30. Comment: Fixed the link title
Jonathan Gao edited Revision 31. Comment: update the architecture diagram
I have a problem with establishing connection in Visual Studio to SQL Azure DB.
The following error is shown in Lesson 2, step 7.
I set IP range even from 0.0.0.0 to 255.255.255.255, but for MicrosoftServices and DevBox rule, but it didn't help.
Do you have idea what can help me?
Microsoft Visual Studio
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
One more clarification: I can access and update DB from the web portal.
Mihail, this error could be related to the Azure July release. Please install the updates specified in this blog: blogs.msdn.com/.../announcing-sql-azure-july-2011-service-release.aspx. Let me know if you resolves the problem.
That helped, thanks Jonathan!
Wonderful article. liked it.