none
CloudStorageAccount.FromConfigurationSetting("DataConnectionString")异常问题,请高手帮忙指导一下,谢谢!.[新手上路] RRS feed

  • 问题

  • 执行CloudStorageAccount.FromConfigurationSetting("DataConnectionString")时,系统总出现异常错误.

    提示我:"SetConfigurationSettingPublisher needs to be called before FromConfigurationSetting can be used "

    但我自己检查后,没发现问题在哪里.请各位大虾,帮忙指导一下.

    我用的开发工具:VS2012 Ultimate

    云计算平台版本:Windows Azure Storage Emulator 3.4.0.0

    问题代码如下:

    一.Azure部分的代码

    namespace AzureService
    {
        public class AzureBlobService
        {
            public static CloudBlobClient InitializeCloudBlobClient(string containerName)
            {
                try
                {
                    CloudBlobClient blobStorage;
                    
                     // 读取Azure Storage 帐号信息[创建]
                      var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

                    // 创建Container
                    blobStorage = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer container = blobStorage.GetContainerReference(containerName);

                 // 注意Container的名字必须为小写
                    container.CreateIfNotExist();

                    // 配置访问权限[创建]
                    var permissions = container.GetPermissions();
                    permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
                    container.SetPermissions(permissions);
                    return blobStorage;
                }
                catch (WebException)
                {
                    System.Diagnostics.Trace.TraceInformation("无法正确连接到Azure Blob Account");
                    throw new WebException("无法正确连接到Azure Blob Account");
                }
            }

    二. Azure Storage运行配置部分

            public override bool OnStart()
            {
                DiagnosticMonitor.Start("DiagnosticsConnectionString");

                 RoleEnvironment.Changing += RoleEnvironmentChanging;

                Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
                {
                    var DataConnectionString = RoleEnvironment.GetConfigurationSettingValue(configName);
                    configSetter(DataConnectionString);

                 });
                return base.OnStart();
            }

    2015年1月26日 13:44

答案

全部回复