Azure MSSQL – Server Firewall Rules

Run these commands on the master table.

First get the existing rules

SELECT * FROM sys.firewall_rules ORDER BY name;

Based on the above query if there are any rules you need to remove get the name and replace Client with the appropriate name

EXECUTE sp_delete_firewall_rule @name = N'Client'
-- https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-delete-firewall-rule-azure-sql-database

If you need to add an IP rule go to https://www.kittell.net/ip.php and update the script below with what is shown on the screen.

-- Create server-level firewall setting for only IP 0.0.0.2  
exec sp_set_firewall_rule N'Example setting 1','0.0.0.2','0.0.0.2';  

-- Update server-level firewall setting to also allow IP 0.0.0.3  
exec sp_set_firewall_rule N'Example setting 1','0.0.0.2','0.0.0.3'; 

Of course if you simply need to allow all Azure (be careful with this one)

-- Enable Windows Azure connections.  
exec sp_set_firewall_rule N'Allow Windows Azure','0.0.0.0','0.0.0.0';
-- https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-set-firewall-rule-azure-sql-database
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.