是否可以在 Azure VIP 交换期间更改连接字符串
我正在尝试在 Azure(九月工具包)中设置暂存和实时环境,并且我想要一个单独的暂存和实时数据库 - 具有不同的连接字符串。显然,我可以在 Visual Studio 中使用 web.config 转换来完成此操作,但是有没有一种方法可以在 VIP 交换期间自动更改连接字符串 - 以便暂存站点指向暂存数据,而实时站点指向实时数据?我不想部署两次。
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. 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? I'd prefer not to have to deploy twice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过管理 API 和 PowerShell Cmdlet,您可以自动化大量的 Azure 平台,其中包括协调 VIP 切换和连接字符串更改。
方法如下:
总而言之,第 5 步将在单个自动化操作中执行 VIP 切换并执行连接字符串更新。
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.
This is the approach:
Taken together, step 5 will perform the VIP switch and perform a connection string update in a single automated operation.
我认为当你进行 VIP 交换时,角色不会发生任何变化。相反,它会更改负载均衡器配置。
因此,您的应用程序中不会发生任何事情导致其更改配置。我唯一能想到的是 URL 在两者之间发生变化。您可以实现根据访问的 URL 选择两个连接字符串之一的代码(假设我们只讨论 Web 角色),但这看起来很混乱。
从根本上来说,我认为问题在于登台不是一个单独的测试环境;而是一个独立的测试环境。它是进入生产的踏脚石。因此,微软的假设是配置不会改变。
I don't believe anything changes as far as the role is concerned when you do a VIP swap. 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. 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.
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.