Managing connection strings Azure Cloud service deployment

878 views Asked by At

I have an azure cloud service project which comprises of one worker role and one web role. I need to have both staging and live deployments but I need them to have different connection strings because the worker role generates lots of data which is reported by the web application and I would not want to have test data in production.

What's the best way to configure this so that I can quickly swap or promote from staging to live and have the connection strings just update without having to republish from visual studio using a different configuration.

4

There are 4 answers

2
daronyondem On

As far as I know there is no automated tooling for this. When you swap, your configuration swaps as well. From what I understand you don't want to swap the configs but just the application.

You might need to build your own swaping tool which would connect to Management APIs and to the swap the way you want.

0
Simon W On

As others have noted this is a known limitation of the VIP swap / slot swap concept that exists in the current generation of Azure Cloud Services (Web Roles / Worker Roles).

One other workaround you could look to use the OnRoleStart event handler and write some custom code to inspect slot in use and update the running configuration.

The way I've seen this sort of problem solved is also to move as much configuration as possible out of local configuration and into a remote database that is then used as the configuration source. This isn't always feasible given the way web.config config sections work in some instances.

1
Maria Ines Parnisari On

You could write a PowerShell script that invokes the Azure Management REST API and changes the connection strings.

    $restEndpoint = "https://management.core.windows.net/$subscriptionId/services/webspaces/$webspace/sites/$website/slotConfigNames"

    $appSettings = $appSettingNames -replace ",", "','"
    $connectionStrings = $connectionStringNames -replace ",", ""","""
    $payload = "{""AppSettingNames"": [""$appSettingNames""], ""ConnectionStringNames"": [""$connectionStrings""]}"

    Invoke-WebRequest -Uri $restEndpoint -Body $payload -CertificateThumbprint $certThumbprint -ContentType "application/json" -Headers @{ "x-ms-version" = "2014-04-01" } -Method POST
1
Ilaiya On

Let me understand you fist. You have two DB(Test and Live) and two environments(Staging and Production CS).

If I am correct please read below.

You should two have two set of connection string in web.config(StagingConStr and ProductionCOnStr). Based on the host(livesite.cloudapp.net or stagingsite.cloudapp.net) you can detect this is in live or in staging. Based on detection you can use the different connection string.

Hope this helps...