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

6.7k views Asked by At

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?

5

There are 5 answers

0
Igorek On BEST ANSWER
0
Anton Moiseev On

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

0
Jonathan McIntire On

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

0
GraemeMiller On

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.