I am developing an ASP.NET MVC 4 / .NET 4.0 Web application in Visual Studio 2012 RC, that is meant to run on Windows Azure, utilizing a SQL Azure database. The solution is source controlled by Team Foundation Service, and I have set up the latter to deploy automatically to Azure whenever I check in.
What I'm wondering is, how do I transform my database connection strings (in Web.config) so that they refer to the production SQL Azure server when the project is deployed on Azure? On my development box I make use of a local SQL Express instance.
I'm open to other methods of deployment (than the TFS automatic service), if there are better ways of doing this.
EDIT: I'm connecting to the database via Entity Framework 5.0.0 RC.
You could also use multiple ServiceConfigurations:

Then, instead of saving your connection string in the web.config you add it as a setting in your ServiceConfiguration:

Since you have multiple configurations you can give a value to SomeConnectionString for each configuration (meaning you can fill in your database settings for the Test, Development and Cloud profiles).
Finally in your code it would be easier to have a factory class that creates the new context based on the connection string in your ServiceConfiguration:
public static class MyDataContextFactory
{
public static MyDataContextEntities Create()
{
return new MyDataContextEntities(RoleEnvironment.GetConfigurationSettingValue("SomeConnectionString"));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With