在C#中获取SQL Azure数据库复制角色

时间:2016-11-11 13:36:53

标签: azure azure-sql-database azure-sdk-.net

我正在尝试使用Azure SDK for .NET检查SQL Azure数据库的复制角色。

我使用SqlManagementClient从订阅中获取数据库,但没有指示复制角色的属性。

我使用以下代码来获取数据库。

var client = GetSqlManagementClient();

var database = client.Databases
    .List("<serverName>")
    .First(x => x.Name == "<databaseName>");

有没有其他方法可以获取我缺少的信息?

1 个答案:

答案 0 :(得分:1)

如果你想读第二个位置,我认为Azure ARM管理可以帮助我们做到这一点。我在当地尝试过,得到的结果如下:

enter image description here

<强> [更新]

这是我的测试代码:

  public async Task<string> GetToken()
        {
            AuthenticationResult result = null;
            string test;
            AuthenticationContext authContext = new AuthenticationContext(adInfo.AuthUrl + adInfo.Telnant);
            ClientCredential cc = new ClientCredential(adInfo.ClientId, adInfo.ClientSecret);
            try
            {
                result = await authContext.AcquireTokenAsync(adInfo.Resource,cc);               
                test = result.AccessToken;
                return test;
            }
            catch (AdalException ex)
            {
                return ex.Message;
            }   
        }

        public async Task GetSQLInfo()
        {
            string token = await GetToken();
            var sqlclient = new SqlManagementClient(new TokenCloudCredentials(adApplication.Subscription, token));
            var data = await sqlclient.Databases.GetAsync("jatestgroup", "jaserver", "jasql");
        }

以下是关于adInfo和adApplication的课程:

  public class AdInfo
    {
        [JsonProperty(PropertyName = "clientid")]
        public string ClientId { get; set; }
        [JsonProperty(PropertyName = "clientsecret")]
        public string ClientSecret { get; set; }
        [JsonProperty(PropertyName = "returnurl")]
        public string ReturnUrl { get; set; }
        [JsonProperty(PropertyName = "telnantid")]
        public string Telnant { get; set; }
        [JsonProperty(PropertyName = "authurl")]
        public string  AuthUrl { get; set; }
        [JsonProperty(PropertyName = "resource")]
        public string Resource { get; set; }

    }
    public class AdApplication
    {
        [JsonProperty(PropertyName = "ARMTemplate")]
        public AdInfo Application { get; set; }
        [JsonProperty(PropertyName = "subscription")]
        public string Subscription { get; set; }
    }

我的Json设置:

{
  "ARMTemplate": {
    "clientid": "****",
    "clientsecret": "****",
    "returnurl": "http://localhost:20190",
    "telnantid": "****",
    "authurl": "https://login.microsoftonline.com/",
    "resource": "https://management.core.windows.net/"
  },
  "subscription": "***"
}

由于此问题与Auth失败更相关。如果我的代码没有给你帮助,我建议你创建一个新的主题并为我们提供更多信息。