Reputation: 1188
I have an ASP.NET MVC 3 application running on Azure. It also uses SQL Azure for a database.
I want to deploy this Application to different instances (Testing, Demo, multiple Productions) and each instance needs it's own unique SQL database.
I know that with the new Azure Tools update, you are able to manage Multiple Service Configurations. This is great and almost solve my problem. The only issue is with the SQL connection strings in the web.config files in the MVC part of the project.
I want the exact same functionality as with the Multiple Service Configurations feature, but to do it for the SQL connection strings.
Thanks for your help!!
Upvotes: 5
Views: 1134
Reputation: 9414
I generally keep my SQL connection strings in the ServiceDefinition.*.cscfg files. That way you get the added advantage of being able to edit them on running instances, which is great for doing VIP swaps.
If you're testing outside the emulator on development machines, it's fairly simple to write an abstraction over config:
class AzureConfig : IConfig
{
public string GetConnectionString(string name)
{
get
{
return RoleEnvironment.GetConfigurationSettingsValue(name);
}
}
}
class OnPremConfig : IConfig
{
public string GetConnectionString(string name)
{
get
{
return ConfigurationManager.ConnectionStrings[name].ConnectionString;
}
}
}
Then set up your IoC container to check RoleEnvironment.IsAvailable and return the relevant type.
Upvotes: 3
Reputation: 2675
.Net configuration transformations should do the job. Like Azure Service Configurations, a separate Web.ConfigurationName.config file is created for each instance you want to deploy to. Building the solution with the proper Configuration (Testing, Demo, etc.) will insert the correct "instance" config values into the Web.config.
Upvotes: 5