c# - 如何从故障转移组名称获取主服务器和辅助服务器名称。有 C# 代码示例吗?

标签 c# azure failover

我需要根据某种逻辑从一个故障转移组更新(基本上是移动数据库)到另一个故障转移组。

有人可以帮助我如何从故障转移组中查找主要和辅助 SQL Server 名称吗?有人可以确认当我们更新故障转移时,Update 方法中的第二个参数是主服务器名称吗?

我们是否也必须更新辅助服务器,或者它会通过复制自动发生?

await client.FailoverGroups
            .UpdateAsync("resourcegroupname", "servername", "newfailovername", 
                         new FailoverGroupUpdate() { Databases = databases});

最佳答案

  • 已创建 SQl 服务器并配置 Azure SQL 自动故障转移 Groups .

enter image description here

enter image description here

  • 在 Azure AD 应用程序中注册应用程序,并为 SQL Server 授予 SQL Server 贡献者角色。
using System;
using Microsoft.Azure.Management.Sql;
using Microsoft.Azure.Management.Sql.Models;
using Microsoft.Rest.Azure.Authentication;

namespace AzureSQLFailoverGroupInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            string tenantId = "72f988bf-86f1-41af-";
            string clientId = "fd6fbe88-d144-4c5c";
            string clientSecret = "3yj8Q~h_COxLnMrJ8";
            string subscriptionId = "b83c1ed3-c5b6-44fb-b5ba-2b83a0";
            string resourceGroupName = "sampath";
            string serverName = "sampath23";
            string failoverGroupName = "sampath123";

            var serviceClientCredentials = ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientSecret).Result;

            SqlManagementClient sqlClient = new SqlManagementClient(serviceClientCredentials)
            {
                SubscriptionId = subscriptionId
            };

            FailoverGroup failoverGroup = sqlClient.FailoverGroups.Get(resourceGroupName, serverName, failoverGroupName);

            string secondaryServer = failoverGroup.PartnerServers[0].Id.Split('/')[8];
       

            Console.WriteLine($"Secondary Server: {secondaryServer}");

            string FailoverGroupName = failoverGroup.Name;

            Console.WriteLine($"failure Server name : {FailoverGroupName}");
          
        }
    }
}
  • 主服务器名称将为 Azure SQL 服务器名称。

enter image description here

关于c# - 如何从故障转移组名称获取主服务器和辅助服务器名称。有 C# 代码示例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76845759/

相关文章:

c# - 断点不会在 Blazor Webassembly 项目、ASP.NET Core 3.1、

c# - 如何尝试将对象转换为 double,如果失败则将其作为字符串?

rabbitmq - 使用 Spring AMQP 和 RabbitMQ HA 进行故障转移

visual-studio - 有谁知道如何修复 "Could not load file or assembly ' Microsoft.WindowsAzure.Storage.Emulator.Controller,版本=3.0.0.0”?

azure - kubernetes 无法查看已挂载的文件夹内容

mysql如何向两台服务器发送数据

java - Apache 、汤姆猫 : Loadbalancing and failover configuration showing blank page.

c# - HTTP 错误 503。80 端口已经空闲时服务不可用

c# - 如何将一个文本文件拆分成多个文件?

authentication - 连接到 HDInsight Web 门户时 Azure HDInsight 身份验证失败