积极答复者
CloudStorageAccount.FromConfigurationSetting("DataConnectionString")异常问题,请高手帮忙指导一下,谢谢!.[新手上路]

问题
-
执行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();
}
答案
-
Hi,
我建议把你的storage client升级到2.0版本以上 (http://www.nuget.org/packages/WindowsAzure.Storage/),然后使用下面的代码再试试。
var storageAccountInfo = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting(configSetting));
希望能帮助你。
Best Regards,
Jambor
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
- 已编辑 Jambor yaoMicrosoft employee, Moderator 2015年1月27日 2:41
- 已标记为答案 Jambor yaoMicrosoft employee, Moderator 2015年2月2日 5:32
全部回复
-
Hi,
我建议把你的storage client升级到2.0版本以上 (http://www.nuget.org/packages/WindowsAzure.Storage/),然后使用下面的代码再试试。
var storageAccountInfo = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting(configSetting));
希望能帮助你。
Best Regards,
Jambor
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
- 已编辑 Jambor yaoMicrosoft employee, Moderator 2015年1月27日 2:41
- 已标记为答案 Jambor yaoMicrosoft employee, Moderator 2015年2月2日 5:32