【问题标题】:How do enable internal Azure Services for SQL Azure in c#如何在 c# 中为 SQL Azure 启用内部 Azure 服务
【发布时间】:2015-10-20 10:57:46
【问题描述】:

如何启用允许的服务:WINDOWS AZURE SERVICES,如 C# 管理门户中所示?

        _client = new SqlManagementClient(GetSubscriptionCredentials());

        var result = _client.Servers.CreateAsync(new ServerCreateParameters
        {
            AdministratorUserName = _config.ServerUserName,
            AdministratorPassword = _config.ServerPassword,
            Location = _config.Location,
            Version = "12.0"
        }, CancellationToken.None).Result;

        var sqlServerName = result.ServerName;

        // This will go away once we can enable the Azure internal firewall settings == Yes
        var ipAddress = _firewallManagement.GetPublicIP();
        var firewall = _client.FirewallRules.Create(sqlServerName, new FirewallRuleCreateParameters("Server", ipAddress, ipAddress));

【问题讨论】:

    标签: c# azure azure-sql-database windows-firewall


    【解决方案1】:

    只需将 0.0.0.0 作为 start_ip_address 和 end_ip_address 像下面的 T-SQL 一样添加到 sys.firewall_rules

    exec sp_set_firewall_rule N'MicrosoftServices','0.0.0.0','0.0.0.0'
    

    不要介意 0.0.0.0 范围,SQL Azure 知道它仅适用于订阅中的 Azure IP。

    select * from sys.firewall_rules
    
    id  name    start_ip_address    end_ip_address  create_date modify_date
    7   MicrosoftService    0.0.0.0 0.0.0.0 2015-07-29 13:34:55.790 2015-07-29 13:34:55.790
    

    Azure SQL 数据库防火墙

    当来自 Azure 的应用程序尝试连接到您的数据库时 服务器,防火墙会验证是否允许 Azure 连接。一种 开始和结束地址等于 0.0.0.0 的防火墙设置 表示允许这些连接。

    https://msdn.microsoft.com/en-us/library/azure/ee621782.aspx#ConnectingFromAzure

    以编程方式添加和删除 SQL Azure 防火墙规则

    http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/adding-and-deleting-sql-azure-firewall-rules-programmatically/

    public void AddFirewallRule(FirewallRule rule)
            {
                using (SqlConnection conn = new SqlConnection(this.ConnectionString))
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = "sp_set_firewall_rule";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = rule.Name;
                    cmd.Parameters.Add("@start_ip_address", SqlDbType.VarChar).Value = rule.startIPAddress.ToString();
                    cmd.Parameters.Add("@end_ip_address", SqlDbType.VarChar).Value = rule.endIPAdress.ToString();
                    cmd.ExecuteNonQuery();
                }
            }
    

    【讨论】:

    • var azureFirewall = _client.FirewallRules.Create(sqlServerName, new FirewallRuleCreateParameters("MicrosoftServices", "0.0.0.0", "0.0.0.0"));
    【解决方案2】:
    猜你喜欢
    • 2015-06-14
    • 2019-07-03
    • 2019-05-02
    • 1970-01-01
    • 2021-07-13
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多