Can I change the connection string while exchanging Azure VIP keys?

I am trying to set up Staging and Live environments in Azure (September Toolkit), and I want a separate Staging and Live database - with different connection strings. Obviously, I can do this with web.config conversions back in Visual Studio, but is there a way to automate changing the connection string during the VIP exchange so that the intermediate site points to intermediate data and the live website to live data? I would rather not turn around twice.

+6
source share
2 answers

I do not believe that something will change when it comes to the role when you do a VIP exchange. Rather, it changes the load balancing configuration.

Nothing happens in your application to force it to change the configuration. The only thing I can think of is that the URL changes between them. You could implement the code that selected one of the two connection strings based on the URL it was addressed to (assuming we are only talking about a web role), but it seems messy.

In essence, I think the problem is that staging is not a separate test environment; This is a step in production. Therefore, Microsoft's assumption is that the configuration does not change.

+9
source

Using the PowerShell Management APIs and cmdlets, you can automate a large number of the Azure platform, and this may include coordinating the VIP switch and changing the connection string.

This is the approach:

  • Add the database connection string to the ServiceConfiguration file.
  • Change your application logic to read the connection string from a specific Azure configuration using RoleEnvironment.GetConfigurationSettingValue rather than the more typical .NET configurationManager.ConnectionStrings API configuration
  • Deploy RoleEnvironmentChanging so that your logic is notified if the Azure service configuration has ever changed. Add the code to update the application connection string here, again using RoleEnvironment.GetConfigurationSettingValue.
  • Deployment for configuration with the ServiceConfiguration parameter for your "intermediate" DB connection string
  • Write a PowerShell script that will trigger the VIP switch (create the Move-Deployment cmdlet from PowerShell Cmdlets for the Windows 2.0 2.0 platform ) and invoke a configuration change with a new ServiceConfiguration file that includes your β€œproduction” DB connection string (see Set- DeploymentConfiguration).

Taken together, step 5 will perform a VIP switch and update the connection string in one automated operation.

+15
source

Source: https://habr.com/ru/post/898302/


All Articles