This is part one in a series of four and will step by step explain how to use WCF services to access SQL Azure Database from Windows Phone 7 app. As an example I will develop a Windows Phone app where the user can create an account and later on log in to the account by user name and password. The accounts are saved in SQL Azure and I am using WCF for communication between the WP7 app and SQL Azure Database.

The first thing you have to do is to buy a Windows Azure service account, you need this to sign up for SQL Azure. Microsoft have several offers at the moment so there is no cost to start with. If you exceed the limits in the offer you have selected, the exceeding usage will be billed. I have a MSDN Ultimate subscription so I get a very good offer to get started with. Go to Windows Azure Offer and sign up with the one that suits you the best.

SQL Azure Project

When your Windows Azure service account is activated go to SQL Azure and sign up with your Windows Azure account. Click the project name you created when getting the Windows Azure service account. Follow the steps creating admin user and password. Make sure that you keep all the information you enter, you need this later on. When I do registrations like this I always have Textpad open and enter all the information there.

Click “Create Database” and enter your database name, select web edition and 1GB. Make sure to keep the server name generated, you need this later on.

SQL Azure Firewall

Select the “Firewall settings” tab and check the “Allow Microsoft Services access to this server.

Click “Add Rule”, enter a name that tells you what computer/network the following IP range is opening up to. If you are on the computer/network you want to use just copy the IP address displayed in both the IP range boxes and submit.

Finally you want to test your connection. Go back to the “Database” tab, select your database and click “Test Connectivity”. Enter the admin user name and password you created earlier. Try to connect and you should get the following message: “Successfully connected to the database”. If not, remember that it can take up to 5 minutes before the firewall rule you added takes effect.

Creating the Database tables in SQL Azure

We will now connect to SQL Azure by using SQL Server Management Studio from SQL Server 2008 R2 (note that the R2 version have a lot of features enabled for SQL Azure). In the connection window you select “Database Engine” and enter the server name you got when setting up the SQL Azure Database, Select “SQL Server Authentication” and the admin user name and password you created for your SQL Azure Database.