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

发布于 2024-12-07 09:37:06 字数 181 浏览 0 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巷子口的你 2024-12-14 09:37:06

通过管理 API 和 PowerShell Cmdlet,您可以自动化大量的 Azure 平台,其中包括协调 VIP 切换和连接字符串更改。

方法如下:

  1. 将数据库连接字符串添加到 ServiceConfiguration 文件中。
  2. 修改应用程序逻辑,以使用 RoleEnvironment.GetConfigurationSettingValue 而不是更典型的 .NET 配置 ConfigurationManager.ConnectionStrings API 从 Azure 特定配置读取连接字符串
  3. 实现 RoleEnvironmentChanging,以便在 Azure 服务配置发生更改时通知您的逻辑。再次使用 RoleEnvironment.GetConfigurationSettingValue 添加代码以在此处更新应用程序的连接字符串。
  4. 使用“暂存”数据库连接字符串的 ServiceConfiguration 设置部署到暂存
  5. 编写一个 PowerShell 脚本,该脚本将调用 VIP 开关(围绕来自 Windows Azure Platform PowerShell Cmdlet 2.0)并使用包含“生产”数据库连接字符串的新 ServiceConfiguration 文件调用配置更改(请参阅Set-DeploymentConfiguration

总而言之,第 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:

  1. Add your database connection string to your ServiceConfiguration file.
  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
  3. Implement RoleEnvironmentChanging so that your logic will be notified if the Azure service configuration ever changes. Add code to update your app's connection string in here, again using RoleEnvironment.GetConfigurationSettingValue.
  4. Deploy to staging with a ServiceConfiguration setting for your "staging" DB connection string
  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)

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

何止钟意 2024-12-14 09:37:06

我认为当你进行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文