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

问题描述 投票:0回答:1

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

有人可以帮助我如何从故障转移组中查找主要和辅助 SQL Server 名称吗?有人可以确认当我们更新故障转移时,

Update
方法中的第二个参数是主服务器名称吗?

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

await client.FailoverGroups
            .UpdateAsync("resourcegroupname", "servername", "newfailovername", 
                         new FailoverGroupUpdate() { Databases = databases});
c# azure failover
1个回答
0
投票
  • 创建了 SQl 服务器并配置 Azure SQL 自动故障转移

enter image description here

enter image description here

  • 在 azure AD 应用程序中注册应用程序,并为 sql Server 授予 SQL Server Contributor 角色。
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 primaryServer = failoverGroup.Name;

            Console.WriteLine($"Primary Server: {primaryServer}");
          
        }
    }
}

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.