Error in Creating Storage Account


  • 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 :


    SetConfigurationSettingPublisher needs to be called before FromConfigurationSetting can be used


    My service Configuration file

    <?xml version="1.0"?>
    <ServiceConfiguration serviceName="StorageTable" xmlns="">
     <Role name="WebRole1">
      <Instances count="1" />
       <Setting name="DiagnosticsConnectionString" value="UseDevelopmentStorage=true" />
       <Setting name="DataConnectionString" value="UseDevelopmentStorage=true" />

    My Service Definition

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




    Regards Thurupathan My blog :
    Tuesday, August 24, 2010 12:44 PM


All replies

  • Hi Thurupathan,

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

            (configName, configSettingPublisher) =>
              var connectionString = RoleEnvironment
    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
  • 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 :
    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 :
    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) =>
        RoleEnvironment.Changed += (sender, arg) =>
          if (arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>().Any((change) => (change.ConfigurationSettingName == configName)))
            if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))


    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
  • Hi,


    Have a good read on the following topic here

    Regards Thurupathan My blog :
    • Marked as answer by thuruvMVP Wednesday, August 25, 2010 12:16 PM
    Wednesday, August 25, 2010 12:16 PM