gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 01:59:35 25 4
gpt4 key购买 nike

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

有人可以帮助我如何从故障转移组中查找主要和辅助 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com