开发者

Windows Azure Connection Strings - How to Handle Local vs. Production?

I'm in the process of deploying some windows azure projects and I've noticed that it's a bit of a pain to constantly switch my role configuration settings from using LocalStorage to actually use my Windows Azure Storage connection strings.

For local development, I want to use this:

UseDevelopmentStorage=true

But for deployed apps, I want to use something like:

DefaultEndpointsProtocol=https;AccountName=myAccountName;AccountKey=blah

I end up either changing my role's configuration connection strings just before I deploy, or if I forget to do that, I'll attempt to go into the Windows Azure portal and change them (but that usually happens after I watch my role instances start and stop over and over).

I feel like I'm missing something basic, but is there a straight-forward way to have the deployment process switch my role connection settings to use the production storage accounts instead of 开发者_运维知识库local storage?


You can use CloudConfigurationManager in Azure SDK 1.7 http://msdn.microsoft.com/en-us/LIBRARY/microsoft.windowsazure.cloudconfigurationmanager

This starts by looking in the ServiceConfiguration.cscfg e.g. ServiceConfiguration.Cloud.cscfg for config setting. If it isn't there it falls back to web.config and app.config

For example

CloudConfigurationManager.GetSetting("StorageConnectionString")

Will look in the appropriate cscfg file for StorageConnectionString setting, then it will search the web.config and then app.config.


If you want to use Visual Studio config transformations, see my answer to the question Panagiotis mentioned.


Switching from one connectionstring to another when moving from development to cloud

Cheers.


If you use CI server you can change the connection string there automatically. Details here.


I've answered a similar question here:

Visual Studio 2010 can apply Debug or Release transformations to Web.config, but what about the Azure settings?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜