none
Error in Creating Storage Account

    Question

  • Hi I'm a newbie to Azure development, I have a problem.

    When I try to create a storage account in my development environment, I get the following error.

    My Code which throws error :

    CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

    Exception :

    InvalidOperationException

    SetConfigurationSettingPublisher needs to be called before FromConfigurationSetting can be used

     

    My service Configuration file

    <?xml version="1.0"?>
    <ServiceConfiguration serviceName="StorageTable" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
     <Role name="WebRole1">
      <Instances count="1" />
      <ConfigurationSettings>
       <Setting name="DiagnosticsConnectionString" value="UseDevelopmentStorage=true" />
       <Setting name="DataConnectionString" value="UseDevelopmentStorage=true" />
      </ConfigurationSettings>
     </Role>
    </ServiceConfiguration>
    

    My Service Definition

    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="StorageTable" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
     <WebRole name="WebRole1">
      <InputEndpoints>
       <InputEndpoint name="HttpIn" protocol="http" port="80" />
      </InputEndpoints>
      <ConfigurationSettings>
       
       <Setting name="DiagnosticsConnectionString" />
       <Setting name="DataConnectionString" />
      
      </ConfigurationSettings>
     </WebRole>
    </ServiceDefinition>
    
    If I have to use the SetConfigurationSettingPublisher how can I do this ? And why I'm getting this exception

     

     

     


    Regards Thurupathan My blog : http://thurupathan.spaces.live.com
    Tuesday, August 24, 2010 12:44 PM

Answers

All replies

  • Hi Thurupathan,

    For some reason the VS CloudService Template doesn't include the following:

    CloudStorageAccount.SetConfigurationSettingPublisher(
            (configName, configSettingPublisher) =>
            {
              var connectionString = RoleEnvironment
                .GetConfigurationSettingValue(configName);
              configSettingPublisher(connectionString);
            }
            );
    
    You always have to add this to your Role's OnStart() method.
    Regards, Patriek
    • Proposed as answer by Rajesh Kolla Tuesday, August 24, 2010 2:53 PM
    • Marked as answer by thuruvMVP Tuesday, August 24, 2010 5:24 PM
    Tuesday, August 24, 2010 12:56 PM
  • You can also use CloudStorageAccount.Parse() if you just want access to the connection string and don't care about the additional features you get by setting a configuration publisher.

    • Marked as answer by thuruvMVP Tuesday, August 24, 2010 5:31 PM
    Tuesday, August 24, 2010 3:00 PM
    Answerer
  • Thanks Patrick van Dorp

    Can you explain me the above code snippet  and what does this do ? Is there any specific reasons for why VS template do not include this in the template

     


    Regards Thurupathan My blog : http://thurupathan.spaces.live.com
    Tuesday, August 24, 2010 5:26 PM
  • Hello Neil Mackenzie


    Your suggestion also works fine; Can you explain what is the different between the above code snippet provided by Patrick Ven Dorp and this Parse ()....


    Regards Thurupathan My blog : http://thurupathan.spaces.live.com
    Tuesday, August 24, 2010 5:36 PM
  • Puboo -

    I explain SetConfigurationSettingsPublisher() in this post. In a comment to that post Aleks Gershaft explains:

    There are few reasons for this functionality:
    1) Remove any dependency of StorageClient on the runtime to allow usage of storage client in variety of non-cloud scenarios. Having to install the SDK just to be able to use a cloud storage because of the convenience method seemed inconvenient.
    2) Allow for automatic key rotation just by a change of configuration without role restat. (NOTE: Windows Azure will not restart your role if you don't ask with the Nov'09 SDK. The default template 'cancels' the RoleEnvironmentChanging event which causes a restart.)
    3) Allow for different ways of delivering the configuration (such as web.config updates in non-Azure environments)

    Patriek's code essentially makes use of 1) and doesn't use 2) and 3). The benefit of 2) is that you can detect changes to the configuration file through the following (see RoleEnvironment.Changed ) which used to be in the template for a web role:

    CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
      {
        configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)); 
    
        RoleEnvironment.Changed += (sender, arg) =>
        {
          if (arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>().Any((change) => (change.ConfigurationSettingName == configName)))
          {
            if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
            {
              RoleEnvironment.RequestRecycle();
            }
          }
        };
      }
    );
    

     

    If you are just trying things out or you don't care about the additional functionality described by Aleks then Parse() works fine.

     

    Tuesday, August 24, 2010 5:47 PM
    Answerer
  • Hi,

     

    Have a good read on the following topic here

     

    http://tobint.com/blog/cloudstorageaccount-setconfigurationsettingpublisher/
    Regards Thurupathan My blog : http://thurupathan.spaces.live.com
    • Marked as answer by thuruvMVP Wednesday, August 25, 2010 12:16 PM
    Wednesday, August 25, 2010 12:16 PM