简体   繁体   English

允许Azure服务通过API连接到Azure SQL Server

[英]Allow Azure services to connect to Azure SQL Server by API

If you create SQL Server by Azure Management Portal, it is possible to allow Azure services to connect by a switch in Configure panel on a server page. 如果通过Azure管理门户创建SQL Server,则可以通过服务器页面上“配置”面板中的开关来允许Azure服务进行连接。 I want to do that by requesting Service Management API. 我想通过请求服务管理API来做到这一点。 Is it possible? 可能吗?

I searched in Operations for Azure SQL Databases and Azure SQL Database REST API Reference . 我在Operations中搜索了Azure SQL数据库Azure SQL数据库REST API参考

Update: code block with example 更新:带有示例的代码块

internal string CreateFirewallRule(string serverName)
{
    var firewallParameters = new FirewallRuleCreateParameters();
    firewallParameters.Name = "AllowAll";
    firewallParameters.StartIPAddress = "0.0.0.0";
    firewallParameters.EndIPAddress = "0.0.0.0";
    var response = _sqlMgmtClient.FirewallRules.Create(serverName, firewallParameters);
    return response.StatusCode.ToString();
}

To allow other Azure Services to connect to your Azure SQL Database Server, you will need to set firewalls accordingly. 若要允许其他Azure服务连接到您的Azure SQL数据库服务器,您将需要相应地设置防火墙。 In Portal.Azure.com , if you go to the server, then settings and select Firewall Rules you can enable other Azure services to connect to the server. Portal.Azure.com中 ,如果转到服务器,则进行设置并选择“防火墙规则”,可以启用其他Azure服务连接到服务器。 This will set up a firewall rule for the range 0.0.0.0 to 0.0.0.0. 这将设置范围为0.0.0.0到0.0.0.0的防火墙规则。

If you would like to do this via REST APIs you can use the Create Firewall Rule API . 如果您想通过REST API进行此操作,则可以使用Create Firewall Rule API You will need to specify the range of 0.0.0.0 to 0.0.0.0 to allow other Azure Services to connect to the server. 您将需要指定0.0.0.0到0.0.0.0的范围,以允许其他Azure服务连接到服务器。 You can also use Azure PowerShell to do this with New Firewall Rule cmdlet . 您还可以使用Azure PowerShell通过New Firewall Rule cmdlet来执行此操作。

Update: code block with example 更新:带有示例的代码块

internal string CreateFirewallRule(string serverName)
{
    var firewallParameters = new FirewallRuleCreateParameters();
    firewallParameters.Name = "AllowAll";
    firewallParameters.StartIPAddress = "0.0.0.0";
    firewallParameters.EndIPAddress = "0.0.0.0";
    var response = _sqlMgmtClient.FirewallRules.Create(serverName, firewallParameters);
    return response.StatusCode.ToString();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM