Tuesday, 18 November 2014

exception of type 'Microsoft.WindowsAzure.Storage.StorageException' occured in Microsoft.WindowsAzure.Storage.dll

exception of type 'Microsoft.WindowsAzure.Storage.StorageException' occured in Microsoft.WindowsAzure.Storage.dll

Additional information: The remote server returned an error: (400) Bad Request.








This kind of exception will come while creation of Container, the container name should be lowercase letters and numbers from 3-24 length.


Container creation in Azure Storage

Every blob in the AzureStorage must reside in the Container.
Today i would like the simple way of creation of Containers from c#.Net, We can also create containers from Azure Management portal.

We need to configure Storage account connection String that i explained my earlier post

Configuring Azure Connection string using .Net Application

Next we need to add namespace declaration in the top of c# programming file, for accessing Azure Storage.

make sure we need to add reference the Microsoft.windowsAzure.Storage.dll

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
  


// Retrieve storage account from connection string.           
 CloudStorageAccount storageAccount = CloudStorageAccount.Parse( 
ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
              
 // Create the blob client.
  CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                

// Retrieve a reference to a container.
  CloudBlobContainer container = blobClient.GetContainerReference("MyPictures");

 // Create the container if it doesn't already exist.
 container.CreateIfNotExists();


By default containers are private in, we can also give the permissions for downloading the blobs.


Monday, 17 November 2014

Configuring Azure Connection string using .Net Application

Hi Folks, Today i will explain about how to configure Azure Connection strings from .NET Application.

There are two ways we can configure from connection string from Azure Cloud service application and  from .NET application.

If your application runs on Azure Virtual Machines or If you are building .NET applications that will run outside azure save your connection String in Web.config OR app.config files.

OR

If your application runs in Azure cloud service you can save the connection string in Azure service configuration system(like *.cscfg nd csdef files).



<add key="StorageConnectionString" value="DefaultEndpointsProtocol=[https/http];AccountName=storageAccount-name;AccountKey=StorageAccount-key" />


DefaultEndPointsProtocaol will be either https or http.

replace the AccountName with your storage account Name.

accountKey will your storageAccount primary or secondary Access Key.


you will find these values from Azure Management Portal --> Storage.


Select your storage and at the bottom Navigational panel you will see the Manage Access Keys




Then it will populate the Manage Access keys Window.