简体   繁体   English

是否可以在Azure VIP交换期间更改连接字符串

[英]Is it possible to change the connection string during an Azure VIP Swap

I'm trying to setup Staging and Live environments in Azure (September toolkit) and I want a separate Staging and Live database - with different connection strings. 我正在尝试在Azure(9月工具包)中设置Staging and Live环境,我想要一个单独的Staging and Live数据库 - 使用不同的连接字符串。 Obviously I can do this with web.config transformations back in Visual Studio, but is there a way I can automate a change of connection string during a VIP-swap - so that the staging site points to staging data and the live site to live data? 显然,我可以在Visual Studio中使用web.config转换来实现这一点,但是有一种方法可以在VIP交换期间自动更改连接字符串 - 以便暂存站点指向暂存数据,将实时站点指向实时数据? I'd prefer not to have to deploy twice. 我宁愿不必两次部署。

With the management APIs and the PowerShell Cmdlets, you can automate a large amount of the Azure platform and this can include coordinating a VIP switch and a connection string change. 使用管理API和PowerShell Cmdlet,您可以自动化大量Azure平台,这可以包括协调VIP交换机和连接字符串更改。

This is the approach: 这是方法:

  1. Add your database connection string to your ServiceConfiguration file. 将数据库连接字符串添加到ServiceConfiguration文件。
  2. Modify your app logic to read the connection string from the Azure specific config by using RoleEnvironment.GetConfigurationSettingValue rather than the more typical .NET config ConfigurationManager.ConnectionStrings API 使用RoleEnvironment.GetConfigurationSettingValue修改应用程序逻辑以从Azure特定配置读取连接字符串,而不是更典型的.NET配置ConfigurationManager.ConnectionStrings API
  3. Implement RoleEnvironmentChanging so that your logic will be notified if the Azure service configuration ever changes. 实施RoleEnvironmentChanging,以便在Azure服务配置发生变化时通知您的逻辑。 Add code to update your app's connection string in here, again using RoleEnvironment.GetConfigurationSettingValue. 使用RoleEnvironment.GetConfigurationSettingValue添加代码以在此处更新应用程序的连接字符串。
  4. Deploy to staging with a ServiceConfiguration setting for your "staging" DB connection string 使用“登台”数据库连接字符串的ServiceConfiguration设置部署到登台
  5. Write a PowerShell script that will invoke the VIP switch (build around the Move-Deployment cmdlet from the Windows Azure Platform PowerShell Cmdlets 2.0 ) and invoke a configuration change with a new ServiceConfiguration file that includes your "production" DB connection string (see Set-DeploymentConfiguration ) 编写将调用VIP开关的PowerShell脚本(从Windows Azure Platform PowerShell Cmdlets 2.0构建Move-Deployment cmdlet)并使用包含“生产”数据库连接字符串的新ServiceConfiguration文件调用配置更改(请参阅Set-部署配置

Taken together, step 5 will perform the VIP switch and perform a connection string update in a single automated operation. 总之,步骤5将执行VIP切换并在单个自动操作中执行连接串更新。

I don't believe anything changes as far as the role is concerned when you do a VIP swap. 当你进行VIP交换时,我不认为角色有任何变化。 Rather, it alters the load balancer configuration. 相反,它会改变负载平衡器配置。

So nothing happens in your app to cause it to change configuration. 因此,您的应用中没有任何事情可以导致它更改配置。 The only thing I can think of is that the URL changes between the two. 我唯一能想到的是URL在两者之间的变化。 You could implement code that chose one of two connection strings, based on the URL with which it was accessed (assuming that we're only talking about a web role), but it seems messy. 您可以根据访问它的URL来实现选择两个连接字符串之一的代码(假设我们只讨论Web角色),但它看起来很混乱。

Fundamentally, I think the issue is that staging isn't a separate test environment; 从根本上说,我认为问题在于升级不是一个单独的测试环境; it's a stepping stone into production. 它是生产的垫脚石。 Thus, Microsoft's assumption is that the configuration doesn't change. 因此,微软的假设是配置不会改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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