A look on Database [SQL Azure] option of new Windows Azure portal

Windows Azure Development portal has been moved to new Silverlight based portal. It has all new look and many new features.

SQL Azure can be explored by selecting Database option from the left panel.

clip_image001

New SQL Azure portal is having very nice Silverlight based user interactive UI and many more operations can be performed through the UI. There is new database manager and it allows us to perform operations at table and row level.

Now we can perform many more operations through Database option of new Windows azure portal.

1. Create a database

2. Create/ delete a table

3. Create/edit/delete rows of table.

4. Create/edit stored procedure

5. Create/edit views

6. Create / execute queries etc. . . .

Let us have a walkthrough on various operations we can perform on Database option of new Windows Azure portal.

To create new Database, select Data base server and from Database section, select Create option.

clip_image003

You will get the below popup, select subscription and server from drop down

clip_image004

Give name of the Database, select Edition and maximum size of the database.

clip_image006

Once database got created, select Manage option from top to open Data Base Manager.

clip_image008

Accept given term and conditions and click Ok.

clip_image009

After Ok, you will get popup asking password to connect to database. Provide password and click on Connect .

clip_image010

After successful connection , you will get a cube providing all the information about the database you connected.

clip_image011

You can perform all the database operations from the top ribbon. You have option to create new query, new table, new view, and new stored procedure

clip_image012

If we want to create new table, click on New Table option from ribbon. We are creating a table with name Blogger. We are giving there columns ID, Name and Technology. From drop down we can select data type for the columns .

clip_image014

Then click on save button at top,

clip_image015

You can navigate between Data Base and Table tab. You can create and delete column from here also. Once you click on save button, you can see table listed at left panel.

clip_image016

At top you can see you have option to navigate either design or data view of table. Click on Data tab to navigate to Data view.

Click on Row to add a Row in the table.

clip_image017

After adding two rows, you can see table as below. You can add and delete rows from top button also.

clip_image019

Now to execute query, select Data Base tab at top and execute query as below,

clip_image021

When you click Execute button at top, you will get output as below,

clip_image023

In this way , you can perform almost all the basic operations from new SQL Azure Data Base Manager.

Windows Azure for Developers Task 10: Creating Storage Account in new Silverlight based Windows Azure Portal

1. Login to Windows Azure Development portal.

2. After login at left panel you can see number of storage and service account in your subscription.

clip_image002

3. Select subscription and storage account option to create new Storage Account. At top left, you will get New Storage Account option. To create new storage account click on new Storage Account.

clip_image004

4. Provide all the required information,

clip_image005

a. Choose subscription.

b. Give unique name URL. It must be combination of only lower letters and numbers.

c. Choose a region, and click on Create.

5. Now you can see storage account has been created.

clip_image006

6. Click on storage account and at right side panel you can see properties.

clip_image007

In properties window we can see URL for BLOB, Queue and Table access. We will have to use these URL to access table, queue or blob.

7. To view the Primary key and Secondary key click on View Button.

clip_image008

In this way , we can create a Storage Account in new Silverlight based Azure Portal.

Windows Azure for Developers Task 9: Hosting WCF Service Role in Windows Azure Hosted Service

In Previous Article We saw How to work with WCF Service Web Role

I am going to extend previous article to publish in hosted service.

Hosting WCF Service Role in hosted service is exactly the same as we host  ASP.Net Web Role.

1. Login to Azure Development portal.

2. Create a new hosted service. If you want you can upgrade any existing hosted service to host WCF Service role also.

Read here, Creating Hosted Service in Windows Azure

3. To upgrade the hosted service ; browse locally

clip_image002

4. Right click on Azure project and select Publish.

5. Now while upgrading hosted service, select browse locally option and navigate to folder containing the files.

6. Once publishing done, you can navigate to the URL. On navigation you may get below error in browser

clip_image004

Do not be panic and append Service1.svc with URL and you will get WCF Service Web Role up and running

clip_image006

7. We can consume service exactly in same way , we consume normal WCF Service.

Windows Azure for Developers Task 8: Working with WCF Service Web Role

WCF Service Role enables us to create WCF service and host in Windows Azure. In this article, we will create a WCF Service Role and host on local development fabric and consume in a console application. In second part of this article we will move WCF Service to Azure portal.

 

To start with,

1. Create a New Project

2. Navigate to cloud tab

3. Create Windows Azure Project
4. Select WCF Service Role from given options.

 

clip_image001

 

If you give a look in solution explorer, you will find in WCF Service Role project contains exactly the same structure and files as of when you create a normal WCF Service Application. It contains ,

 

1. IService1.cs (Service Contract )
2. Service1.svc.cs ( Service definition file )
3. Web.config ( configuration for EndPoints)

 

We can modify these files accordingly for our purpose in exactly the same way; we do in usual WCF Service Application.

 

Let us modify Service Contract as below,

 

IService1.svc


using System.ServiceModel;

namespace WCFServiceWebRole1
{
 [ServiceContract]
 public interface IService1
 {

[OperationContract]
 string GetData(int value);

 }
}

 

And service definition would be,

 

Service1.svc.cs

namespace WCFServiceWebRole1
{

 public class Service1 : IService1
 {
 public string GetData(int value)
 {
 return string.Format("You entered: {0}", value);
 }

 }
}

 

 

Leave default configuration in Web.Config

 

Make sure you have set Windows Azure project as Startup project and run the application. In browser you will get below error message.

 

clip_image003

 

Ignore this message and append service.svc with URL, so now URL would be http://127.0.0.1:81/service1.svc. Service.svc is name of the service definition.
After appending you will get usual WCF Service message in browser.

 

clip_image005

 

To test this WCF Service role in a console client,

 

1. Create a console application project
2. Add Service Reference by providing URL http://127.0.0.1:81/service1.svc

 

clip_image006

 

Now we will make a normal service call,

 

Program.cs

using System;
using ConsoleApplication14.ServiceReference1;

namespace ConsoleApplication14
{
 class Program
 {
 static void Main(string[] args)
 {
 Service1Client proxy = new Service1Client();
 var result = proxy.GetData(99);
 Console.WriteLine(result);
 Console.ReadKey(true);
 }
 }
}

 

 

Now when you run you may or may not get below exception.

 

clip_image007

 

To solve above exception, we have to edit App.Config file. We need to change

 

clip_image009

 

127.0.0.1 to localhost. Because it might be the case console application is not able to resolve 127.0.0.1 . we need to change to localhost.
clip_image011

 

Now on running we will get below output

 

clip_image013

 

One behavior need to be noticed here is that sometime you may get time out exception after changing 127.0.0.1 to localhost also. In my further articles, I will drill down this unwanted behavior.

Type casting with is and as operator in C#

I have been seeing many developers are casting between two types using is operator. As we know, we do have as operator also for type casting.

For purpose of this article, we are going to use below two classes,

clip_image002

Very first let us try to understand, how is operator works?

clip_image004

So , if we are running below code , we will get output as true because ofccouse p is a Player.

clip_image006

Now let us modify code a bit and check whether p is compatible to Math class or not? Since p is instance of class Player and Player class does not have Math class in hierarchy tree, so output we will get false.

clip_image008

If we compare an object against null, we will get always an output as false.

Normally we use is operator like below,

clip_image010

In above snippet, C# checks type compatibility twice and it costs the performance. So to simplify above code and improve performance C# gives us as operator to compare.

clip_image012

as operator find type compatibility, If an object is not compatible with given type then as operator returns null.

clip_image013