locked
Validate Azure storage account Name RRS feed

  • Question

  • Hi,

    I want to validate Azure Storage account name. I tried it with the below code.

    StorageCredentialsAccountAndKey

     

    storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(pAccountName, pAccountKey);

    CloudStorageAccount cloudStorageAccount = new CloudStorageAccoun(storageCredentialsAccountAndKey, true);

    var

    cloudTableClient = cloudStorageAccount.CreateCloudTableClient();

     

     

    IEnumerable<string

    > tableNames = cloudTableClient.ListTables();

     

    int

    totaTables = tableNames.Count();

    This is validating the Storage Account Key, But if the Storage Account name is wrong and Storage Account Key is correct it is working and ging the no of tables as 0. But I want to validate the Storage account name also.

    Anyone who have idea to solve this please reply me.

    Thanks in Advance.

    Monday, November 14, 2011 11:15 AM

Answers

  • Below code is working. it is validating both Storage Account Name and Key:

    StorageCredentialsAccountAndKey

     

    storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey

    (pAccountName, pAccountKey);

     

    CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentialsAccountAndKey, true);

     

     

    varcloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();

    int i = cloudBlobClient.ListContainers().Count();

     
    • Marked as answer by Aachi Tuesday, November 15, 2011 7:53 AM
    Tuesday, November 15, 2011 7:52 AM

All replies

  • Could you explain more about what's happening? If I use a bad account/key combination, I get an exception about authorization when I try to list the tables.

    I'm not sure what you mean by "if the Storage Account name is wrong and Storage Account Key is correct." Either the pair is correct (the account exists and that is the correct key) or the pair is incorrect (the account name and key don't match). I don't know what it means for the account name to be wrong but the key to be correct.

    Monday, November 14, 2011 1:56 PM
  • If you have multiple configuration(.cscfg) files , make sure that you are refering to same configuration file for both making your changes to storage account name/key and verifying code for the same.

    HTH.


    Please mark it as answer by clicking on "Propose As Answer", if it helps. My Blog : http://dotnetizen.blogspot.com
    Monday, November 14, 2011 3:06 PM
  • I will explain you my problem: case 1: Storage Accout Name:Correct , Storage Accout Key:wrong, It is throwing error in case 1 case 2: Storage Accout Name:wrong , Storage Accout Key:Correct, It is not throwing error in case 2. Simple it is saying No of table=0 But I want it to throw error in case 2 also. Please reply me if anyone have idea to solve this
    • Edited by Aachi Tuesday, November 15, 2011 4:46 AM Alignment
    Tuesday, November 15, 2011 4:43 AM
  • I still don't understand what it would mean to have the storage account name wrong but the key correct.

    Maybe you can email me an account and key that you're trying that shows the problem. My email address is Steve.Marx@microsoft.com.

    Tuesday, November 15, 2011 7:18 AM
  • Below code is working. it is validating both Storage Account Name and Key:

    StorageCredentialsAccountAndKey

     

    storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey

    (pAccountName, pAccountKey);

     

    CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentialsAccountAndKey, true);

     

     

    varcloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();

    int i = cloudBlobClient.ListContainers().Count();

     
    • Marked as answer by Aachi Tuesday, November 15, 2011 7:53 AM
    Tuesday, November 15, 2011 7:52 AM