Windows azure local storage setconfigurationsettingpublisher needs to be called before fromconfigurationsetti

Source: Internet
Author: User

When Windows azure storage service was opened today, we encountered a problem:

Execute the following initialization StorageCode

 
// Read account configuration settingsvar storageaccount = cloudstorageaccount. fromconfigurationsetting ("dataconnectionstring ");

Throw an exception

I found some information on the Internet and did not get any help. So I went back to the Windows azure White Paper and looked at the example descriptions. I found that a very important piece of code was missing.

This is my code

Namespace wcfservicewebrole {public class webrole: roleentrypoint {public override bool onstart () {diagnosticmonitor. Start ("diagnosticsconnectionstring"); // information about processing configuration changes, // see http://go.microsoft.com/fwlink? Link id = The msdn topic on 166357. Roleenvironment. changing + = roleenvironmentchanging; return base. onstart ();} private void roleenvironmentchanging (Object sender, roleenvironmentchangingeventargs e) {// If the configuration is changed, if (E. changes. any (change => change is roleenvironmentconfigurationsettingchange) {// set. set Cancel to true to restart this role instance E. cancel = true ;}}}}

 

 

modified Code

Namespace wcfservicewebrole {public class webrole: roleentrypoint {public override bool onstart () {diagnosticmonitor. Start ("diagnosticsconnectionstring"); // information about processing configuration changes, // see http://go.microsoft.com/fwlink? Link id = The msdn topic on 166357. Roleenvironment. changing + = roleenvironmentchanging; // you must call cloudstorageaccount when using configurationsettings in the configuration file. setconfigurationsettingpublisher // specifies the action Microsoft takes when the configuration file is changed after it is published. windowsazure. cloudstorageaccount. setconfigurationsettingpublisher (configname, configsetter) => {configsetter (Microsoft. windowsazure. serviceruntime. roleenvironment. getconfigurationsettingvalue (configname); roleenvironm Ent. changed + = (sender, ARG) => {If (Arg. changes. oftype <roleenvironmentconfigurationsettingchange> (). any (Change) => (change. configurationsettingname = configname) {If (! Configsetter (roleenvironment. getconfigurationsettingvalue (configname) {roleenvironment. requestrecycle () ;}}; return base. onstart ();} private void roleenvironmentchanging (Object sender, roleenvironmentchangingeventargs e) {// If the configuration is changed, if (E. changes. any (change => change is roleenvironmentconfigurationsettingchange) {// set. set Cancel to true to restart this role instance E. cancel = true ;}}}}

The reason is that the setconfigurationsettingpublisher method is missing,

This method is not automatically generated when a project is created in vs2010, resulting in failure of the subsequent cloud storage account.

POs: at present, cloud computing is just getting started in Windows azure in China. This tutorial is rarely limited to general entry-level Tutorials that encounter difficult problems.Technical materials

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.