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