Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Posts Tagged ‘azure’

Windows Azure – Connecting to SQL Azure using Management Studio

Posted by Paul on November 13, 2011

Another reusable tool over the SQL Azure is Management Studio. In this article we are going to explore the aspects regarding SQL Server Management Studio 2008.

clip_image002

Version

We can use the Management Studio for SQL Server 2008 R2. If you do not have this version installed, you can download an express edition which is free. (Please note that this is a CTP version)

Note: The Enterprise Manager associated with SQL Server 2000 and the Management Studio of SQL Server 2005 cannot be used with SQL Azure.

Download

You can download the SQL Azure supported version of Management Studio below:

32 bit

64 bit

Based on your Processor Architecture, download the appropriate version. The setup file should be around 160 MB in size.


Running the Setup

After running the setup you can view the following screen.

clip_image004

Use the highlighted option to proceed. (There will be a series of pre-requisites for the installation)

Run the Management Studio

After installation open the management studio from the start menu.

Connecting to SQL Azure

Open the Management Studio and in the appearing login dialog enter your SQL Azure credentials.

clip_image006

You will be taken to the Explorer view after the successful login. Now you can create new database, table, run SQL queries in the management studio. These activities are familiar with almost all developers and so not worth depicting. In the next article we will discuss another replacement for Management Studio.

Note: The OData (OpenData) feature of SQL Azure allows us to read the data over the browser, write LINQ queries on it etc.

Summary

In this article we explored connecting to online SQL Azure database. This advantage allows us to reuse our familiarity with SQL Server Management Studio.

Advertisements

Posted in C# | Tagged: , , | Leave a Comment »

Windows Azure – Connecting to SQL Azure using Management Studio

Posted by Paul on November 13, 2011

Another reusable tool over the SQL Azure is Management Studio. In this article we are going to explore the aspects regarding SQL Server Management Studio 2008.

clip_image002

Version

We can use the Management Studio for SQL Server 2008 R2. If you do not have this version installed, you can download an express edition which is free. (Please note that this is a CTP version)

Note: The Enterprise Manager associated with SQL Server 2000 and the Management Studio of SQL Server 2005 cannot be used with SQL Azure.

Download

You can download the SQL Azure supported version of Management Studio below:

32 bit

64 bit

Based on your Processor Architecture, download the appropriate version. The setup file should be around 160 MB in size.


Running the Setup

After running the setup you can view the following screen.

clip_image004

Use the highlighted option to proceed. (There will be a series of pre-requisites for the installation)

Run the Management Studio

After installation open the management studio from the start menu.

Connecting to SQL Azure

Open the Management Studio and in the appearing login dialog enter your SQL Azure credentials.

clip_image006

You will be taken to the Explorer view after the successful login. Now you can create new database, table, run SQL queries in the management studio. These activities are familiar with almost all developers and so not worth depicting. In the next article we will discuss another replacement for Management Studio.

Note: The OData (OpenData) feature of SQL Azure allows us to read the data over the browser, write LINQ queries on it etc.

Summary

In this article we explored connecting to online SQL Azure database. This advantage allows us to reuse our familiarity with SQL Server Management Studio.

Posted in C# | Tagged: , , | Leave a Comment »

Windows Azure – Adding Certificate in Portal

Posted by Paul on November 13, 2011

Certificates are required to for authentication in a much secured way. In Windows Azure portal we can create certificates.

In this tutorial we are following the steps to create a certificate which will be used in the next article.

The activities involved are:

  • Create the certificate
  • Upload certificate to portal

Open the Visual Studio command prompt as administrator.

clip_image002

On the command prompt, enter the following command to create certificate named MyCertificate.cer.

makecert -sky exchange -r -n “CN=MyCertificate” -pe -a sha1 -len 2048 -ss My “MyCertificate.cer”

clip_image004

If the reply is Succeeded you are ready with the certificate. Note the path where the certificate is created.

Now we need to upload the certificate to Windows Azure Portal. For this sign in to the portal and choose the Management Certificates item as shown below.

clip_image006

In the appearing screen below, click on the Add Certificate button

clip_image008

A new dialog will be appearing.

clip_image010

Locate the certificate file (MyCertificate.cer) using the Browse button above and click Ok.

Now within a few minutes the certificate will be added to the account. See the status below.

clip_image012

If you can see the new certificate item the adding of certification succeeded.


Summary

In this article we have seen how to create a certificate and add to windows azure portal. The certificate will be used in the next article for MMC tool.

Posted in C# | Tagged: , , , | Leave a Comment »

Windows Azure – Adding Certificate in Portal

Posted by Paul on November 13, 2011

Certificates are required to for authentication in a much secured way. In Windows Azure portal we can create certificates.

In this tutorial we are following the steps to create a certificate which will be used in the next article.

The activities involved are:

  • Create the certificate
  • Upload certificate to portal

Open the Visual Studio command prompt as administrator.

clip_image002

On the command prompt, enter the following command to create certificate named MyCertificate.cer.

makecert -sky exchange -r -n “CN=MyCertificate” -pe -a sha1 -len 2048 -ss My “MyCertificate.cer”

clip_image004

If the reply is Succeeded you are ready with the certificate. Note the path where the certificate is created.

Now we need to upload the certificate to Windows Azure Portal. For this sign in to the portal and choose the Management Certificates item as shown below.

clip_image006

In the appearing screen below, click on the Add Certificate button

clip_image008

A new dialog will be appearing.

clip_image010

Locate the certificate file (MyCertificate.cer) using the Browse button above and click Ok.

Now within a few minutes the certificate will be added to the account. See the status below.

clip_image012

If you can see the new certificate item the adding of certification succeeded.


Summary

In this article we have seen how to create a certificate and add to windows azure portal. The certificate will be used in the next article for MMC tool.

Posted in C# | Tagged: , , , | Leave a Comment »

Windows Azure – Create Queue in Storage Account

Posted by Paul on November 6, 2011

In this article we can explore the queue creation in storage account.

As a refresh, I would like to repeat that there are 3 types in Azure Storage

  • Blob
  • Table
  • Queue

The Table creation was explored in the previous article. Queue creation will be explored here.

Concepts in Queue

Following are the key concepts in queue.

  • FIFO implementation
  • Messages are added to end of the Queue and processed from the front
  • Queues provides a good way of Front end and Back end decoupling

In the real world example the user can queue a job through the web role (front end) and the job can be processed by a worker role (back end). This gives an opportunity to decouple the web role and worker role.

clip_image002

Note: Blob are stored in container, Entity in table and Message in Queue

The steps involved in creating a queue are following:


Step 1:Create new project

As always create a new azure project and add a web role into it. Now add reference to the StorageClient dll file.

clip_image004

Step 2: Modify the Default.aspx

Place a new label control on the aspx page and add the following code in the page load event.

protected void Page_Load(object sender, EventArgs e)

{

StorageCredentialsAccountAndKey accountAndKey = new StorageCredentialsAccountAndKey("account", "key");

CloudStorageAccount account = new CloudStorageAccount(accountAndKey, true);

CloudQueueClient client = account.CreateCloudQueueClient();

CloudQueue queue = client.GetQueueReference("workitems");

queue.CreateIfNotExist();

CloudQueueMessage message = new CloudQueueMessage("Test Work Item");

queue.AddMessage(message);

// Populate the messages

message = queue.GetMessage();

if (message != null)

Label1.Text = "Message in Queue: " + message.AsString;

}

Place your account name and key in the credentials. Ensure that the queue name is lower case (upper case will throw exception)

The above code will create a new message in the queue and after that it will retrieve the queue message and show in the page.


Important Classes

The important classes in the queue processing are stated below:

· CloudQueueClient

  • CloudQueue
  • CloudQueueMessage

The CloudQueueClient class takes care of getting the queue reference from the storage account. The CloudQueue class takes care of the holding the queue object. The CloudQueueMessage holds the actual message for the queue.

Summary

In this article we have seen how to put message into Queue and later retrieve it. The code attached contains the projects discussed above.

Posted in Azure | Tagged: , , | Leave a Comment »

Create Table in Storage Account

Posted by Paul on November 6, 2011

In this article we can explore the table creation in storage account.

As a refresh, I would like to repeat that there are 3 types in Azure Storage

  • Blob
  • Table
  • Queue

The Blob creation was explored in the previous article. Table creation will be explored here.

Concepts in Table

Following are the key concepts in table.

  • Tables allow structure data storage
  • There can be 0..n tables in a storage account
  • Table store data as a collection of entities
  • Entity have a primary key and properties as key value pair

Note: The table we discuss here is not entirely same as our database table. The database table will be discussed in SQL Azure. In Blob Service, the data is stored in containers. But in Table Service, data is stored in tables.

The steps involved in creating a table are following:

Step 1:Create new project

As always create a new azure project and add a web role into it. Now add reference to the StorageClient dll file.

clip_image002

Step 2: Define the Entity

Now we need to define the entity with the required properties, create a new class, derive it from TableStorageEntityand define the following properties in it.

Our entity class is derived from TableStorageEntitybecause this class takes care of the key properties like PartitionKey, RowKey and necessary attributes.

Step 3: Code Part

Now we can write the code to do the following activities:

  • Do account authentication
  • Create Table client
  • Create table in account
  • Add the new entity to tabl

The following code performs the following:

protected void Page_Load(object sender, EventArgs e)

{

StorageCredentialsAccountAndKey accountAndKey = new

StorageCredentialsAccountAndKey("youraccount", "key");

CloudStorageAccount account = new CloudStorageAccount(accountAndKey, true);

CloudTableClient client = account.CreateCloudTableClient();

client.CreateTableIfNotExist("Contact");

TableServiceContext tableContext = new

TableServiceContext(account.TableEndpoint.ToString(),

account.Credentials);

Contact contact = new Contact();

contact.PartitionKey = "1";

contact.RowKey = "1";

contact.Name = "Contact1";

contact.Address = "Address1";

tableContext.AddObject("Contact", contact);

tableContext.SaveChanges();

}

The account name and key can be obtained as explained in the previous article.

Note: We are setting the PartitionKey and RowKey as “1” for demo purposes. The PartitionKey represents the partition identifier where the table is stored. The RowKey should be the unique identifier to the entity. More Info

The classes involved for resembles the ADO.NET Entity Framework classes.

Step 4: Viewing the entity inserted

You can use the Server Explorerto see the new entity inserted as shown below.

clip_image004

Summary

In this article we have seen how to define a table and insert entity into it.

Posted in Azure | Tagged: , , , | Leave a Comment »

Create Blob in Storage Account

Posted by Paul on November 6, 2011

In this article we are trying to create the blob in the real storage account we created. As we are aware of the basics of blob and related classes in Windows Azure this article is emphasizing on the storage account related activities.

The core classes involved in Winows Azure blob activities were:

· CloudStorageAccount

· CloudBlobClient

· CloudBlobContainer

· CloudBlob

Connecting to the Storage Account

For connecting to the storage account, we need the correct Account Name and Key.

For obtaining the account name do the following:

  • Sign in to Windows Azure Portal
  • Click the Hosted Services group from left pane
  • Click the Storage Accounts from left pane
  • Select the account we created previously
  • From the right pane you can get the Name of the account

clip_image002

For obtaining the key do the following:

  • Click on the View button of Primary access key
  • On the appearing dialog click the copy button and you are ready with the key

clip_image004

Note In the above dialog we can see Primary access key and Secondary access key. Both can be used for the account authentication purpose. The secondary access key is used for making the application available during change in primary access key. You can read about it here

Modify the Account Access Code

We have to modify the account specification code as given below.

StorageCredentialsAccountAndKey accountAndKey = new StorageCredentialsAccountAndKey(“account”, “primarykey”);

CloudStorageAccount account = new CloudStorageAccount(accountAndKey, true);

Use your account name and the key in the account and primarykey texts.

Now the code is ready for connecting to the online storage account

Execute the Code

Now you can execute the code and view the result in browser as shown below.

clip_image006

If you can see the file name you have uploaded, then the online connection to storage account is success.

Using the Server Explorer for viewing Blobs

Visual Studio provides a convenient way to see the blobs we have uploaded. For viewing them use the View > Server Explorer command.

clip_image008

In the above dialog, right click on Windows Azure Storage tree item.

clip_image010

In the above dialong, click on the Add New Storage Account menu item.

Specify the account credentials in the appearing dialog.

clip_image012

Click the Ok button to continue.

A new tree item with your Account Name will be created and expanding that you can access your blob and container. Click on the container and a new view is opened showing the list of files in the container.

clip_image014

In the above window you can see the File.txt blob item you have created. This confirms the creation of blob in online storage account.

Summary

In this article we have seen how to connect to the online storage account and create blobs. The Server Explorer helps in viewing the blobs created.

Posted in Azure | Tagged: , , | Leave a Comment »

Create Blob in Storage Emulator

Posted by Paul on November 6, 2011

In this article we are trying to create a blob in the storage emulator. The same blob creation can be done on storage account too.

Some Theories on Blob in Azure

  • Blob represents Binary Large Object
  • It can contain text and binary data
  • Containers are required for storing Blobs
  • Containers can be private and public
  • Blob can have metadata

The storage account created should be having containers for storing blobs. The containers can be viewed as folders.

Eg: Documents, Images etc.

The private containers are private to the storage account and only the account holder can access it. The urls in public containers are accessible over the internet.

The Blob can have metadata as collection of key value pair. We can store the information like Author, Date, and Description etc. for the blob.

Advantages of Blob

The blob helps us to store image files, documents etc. which are normally unstructured data. If the same is stored in database, it results in performance problems.

Without a blob service, the manual programming requires much effort to manage the large sized files.

The activities include:

  • Creating a File/Folder infrastructure in the web application space
  • Create with multipart uploads for uploading large files
  • Create a database table for managing the metadata
  • Create the corresponding entities
  • Manage with backup and restore of the large files involving high network traffics

Thanks to Microsoft, the blob service does all the things for us at a lower cost.


Steps in creating Blob

Following are the steps in creating a blob.

clip_image002

The first step (Create Storage Account) was already done from our side and we need to proceed with the further steps to create the blob.

There are two ways of creating container and blob

  • Through Program
  • Using Windows Azure Management Tool

In this article we are proceeding with the first way and the second way will be discussed in another upcoming article.

Following are the steps involved in the creation of container and blob.


Step 1: Create new web azure project

Create a new Windows Azure project and add a web role into it. The solution explorer would look like below.

clip_image004

Step 2: Add reference to library files

We need to add specific reference to the following Windows Azure SDK dll file.

Dll: Microsoft.WindowsAzure.StorageClient.dll

Location: C:\Program Files\Windows Azure SDK\v1.5\ref

clip_image006

Step 3: Create the container

Now open the code view of Default.aspx, place a label control on it and enter the following code.

protected void Page_Load(object sender, EventArgs e)

{

CloudStorageAccount account = CloudStorageAccount.DevelopmentStorageAccount;

CloudBlobClient client = account.CreateCloudBlobClient();

CloudBlobContainer container = client.GetContainerReference("documents");

container.CreateIfNotExist();

CloudBlob blob = container.GetBlobReference("File.txt");

blob.UploadFile(Server.MapPath("~/File.txt"));

// show the blobs

Label1.Text = "Blobs inside container: <br>";

foreach (IListBlobItem item in container.ListBlobs())

Label1.Text += item.Container + " " + item.Parent.ToString() + " " +

item.Uri.ToString() + " <br>";

}

Note: The container name as documents. We need to ensure the name should be lowercase and additional restrictions. An invalid naming convention will throw exception StorageClientExceptionwith message “One of the request inputs is out of range.”

There are two methods in class CloudBlobContainer for creating the container.

  • Create()
  • CreateIfNotExist()

Using the CreateIfNotExist() method is advised as it won’t throw the exception if a container already exists with the given name.

Step 4: Create the blob file

In the web role project add a file named File.txtwith some text contents. Execute the application and you can see the following result.

clip_image008

Note: The local Storage Emulator is used in the above code for creating the container and blob. In the real scenario of uploading to online storage account, we need to modify the line:

clip_image010

as shown below

clip_image012

Summary

In this article we have learned some information on blob, container and how to create them programmatically. The associated source code can be used to test blob creation in your local machine.

Posted in Azure | Tagged: , , | Leave a Comment »

Create Storage Account

Posted by Paul on November 6, 2011

For storing in Windows Azure Storage we need to create a Storage Account. The advantages of storage account are following:

  • Exposed over HTTP, REST and OData
  • Permanent Data Storage
  • 3 Types of Storage: Blob, Table and Queues
  • Accessible from anywhere
  • Exposed to Pricing

Please remember that the previous Local Storage was temporary storage and only accessible inside the azure environment. So the Storage Account gains more advantages than local storage.

OData is the synonym for Open Data Protocol.

The data in the storage account is accessible from a mobile application, windows application or other web role.

For using the Windows Azure Storage, we need to create a Storage Account which is explained in step by step.

Step 1: Select the Storage Accounts item from portal

Sign in to the Windows Azure Portal and select the Storage Accounts link from the left pane. The order of clicks are depicted in the figure below.

clip_image002

Step 2: Click on the New Storage Account button

From the ribbon on top, click on the New Storage Account button as shown below

clip_image004

Step 3: Enter the details

On clicking the button from previous step, the following dialog box appears.

clip_image006

Enter the details for your account.

URL: The url should be unique and in lower case. The uniqueness prevents any duplicate url from other accounts.

Region: Choose a region closer to your location or the deployed application location so that the access will be faster.

After entering the details click the Ok button to continue

Step 4: Wait for Account Creation

Now there will be a delay due to the account creation, DNS configuration activities. Wait for a few minutes and you will be ready with the account as shown below.

clip_image008

Once the status changed to Created you are ready with the account. The account usage for storing blob, table and queues will be demonstrated in further articles.

Summary

In this article we have seen how to create a Storage Account through the Windows Azure Portal. This storage account is needed to use Windows Azure Storage types like tables, queues and blobs.

Posted in Azure | Tagged: , , | Leave a Comment »

Local Storage Example

Posted by Paul on November 6, 2011

In this article, we are trying to experiment the local storage feature of Windows Azure. From the previous article we found that local storage is one of the primitive storage mechanisms in Windows Azure.

The core features of Local Storage are:

  • Temporary Storage
  • Feature provided by the Operating System
  • Similar to Hard Drive
  • Exposed as logical file system
  • .Net Directory/File IO Framework used to access it
  • Can be used for storing Cache items

Creating a Local Storage

Here we are creating a local resource through the step by step activities.

Step1: Create new Web Role project

You will be familiar with web role creation and you can repeat the same. After the solution is created, the Solution Explorer will be looking like below:

clip_image002

Step 2: Open the local storage pane

Now double click on the WebRole1 item shown above to open the project configuration, Form there click the Local Storage pane item.

clip_image004

Step 3: Add a new Local Storage item

Add a new local storage items by clicking the Add Local Storage button. Rename it to TestStorage Change the Size to 10 MB as shown in the figure and save the configuration.

clip_image006

The above change will modify the configuration file of the application.

Step 4: Show Information about the Local Resource

Now we can place a label on the page, rename it to InfoLabel. Then on the page load event we can access the local resource and show the properties it has.

clip_image008

The RootPath property gives the current path of the resource in machine.

The MaximumSizeInMegabytes property returns the size allocated to it.

On executing the application we can see the following output.

clip_image010

Step 5: Start using the folder

Now we can use the above folder for our storage purpose. We can create folder, files inside it.

Create a new button on the page and name it as CreateFolderAndFileButton. On click of the button place the code to create a directory and file.

protected void CreateFolderAndFileButton_Click(object sender, EventArgs e)

{

LocalResource resource = RoleEnvironment.GetLocalResource(“TestStorage”);

Directory.CreateDirectory(resource.RootPath + “\\NewFolder”);

File.Create(resource.RootPath + “\\NewFile.txt”);

ShowContents(resource.RootPath);

}

private void ShowContents(string path)

{

InfoLabel.Text = “Directories inside it: <br>”;

foreach (string dir in Directory.GetDirectories(path))

{

InfoLabel.Text += dir + “<br>”;

}

InfoLabel.Text += “<br>Files inside it”;

foreach (string file in Directory.GetFiles(path))

{

InfoLabel.Text += file + “<br>”;

}

}

Execute the application and on clicking the button we can see the following output.

clip_image012

Summary

In this article we have found how to use the local storage feature of Windows Azure and creating folder and file inside it.

Posted in Azure | Tagged: , , , , | Leave a Comment »