简体   繁体   中英

Managing connection strings Azure Cloud service deployment

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.

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

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.

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM