How do I enable allowed services : WINDOWS AZURE SERVICES as seen in the Management Portal in 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));
Just add 0.0.0.0 as start_ip_address and end_ip_address like the T-SQL below to sys.firewall_rules
exec sp_set_firewall_rule N'MicrosoftServices','0.0.0.0','0.0.0.0'
Don't mind the 0.0.0.0 range, SQL Azure knows it is only for Azure IPs in your subscription.
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 Database Firewall
When an application from Azure attempts to connect to your database server, the firewall verifies that Azure connections are allowed. A firewall setting with starting and ending address equal to 0.0.0.0 indicates these connections are allowed.
https://msdn.microsoft.com/en-us/library/azure/ee621782.aspx#ConnectingFromAzure
Adding and Deleting SQL Azure firewall rules programmatically
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With