Windows Azure SQL Database : How to manage your firewall rules using SQL Commands


You can manage your Windows Azure SQL Database firewall rules using SQL Commands.

For a general overview of securing your Windows Azure SQL Database please check my previous article : Secure Your Windows Azure SQL Database.

There are two types of Windows Azure SQL Database firewall rules

1. Server-Level Firewall Rules

2. Database-Level Firewall Rules

You can manage Server-Level or Database-Level using SQL Commands.

You can run these commands using :

  • SQL Server Management Studio
  • Visual Studio
  • Application or Web Site
  • Windows Azure SQL Database Management Portal
  • etc


You can read my previous article How to create Windows Azure SQL Database for a quick overview of how you can connect to Windows Azure SQL Database using SQL Server Management Studio or Visual Studio.


Depending to firewall rule type you should run different types of scripts in different databases.


Server-Level Firewall Rules : These rules are effective for all your databases in your database server. You can allow IP addresses allowed to connect to your server. It is also possible to allow your Windows Azure cloud services to access to your database server. These rules are stored in master database.

In order to create, delete or view Server-Level firewall you should run your commands in master database with a server-level principal login.



-- view firewall settings
select * from sys.firewall_rules

-- enable Windows Azure connections
exec sp_set_firewall_rule N'Allow WA','',''

-- create new firewall setting for only IP
exec sp_set_firewall_rule N'SingleIPFW','',''

-- create new firewall setting for IP Range -
exec sp_set_firewall_rule N'IPRangeFW','',''

-- create new firewall setting for access to all
exec sp_set_firewall_rule N'AllFW','',''

-- update firewall setting to also allow IP
exec sp_set_firewall_rule N'SingleIPFW','',''

-- Remove 'SingleIPFW' firewall setting
exec sp_delete_firewall_rule N'SingleIPFW'

Database-Level Firewall Rules : Database-Level Firewall rules enable clients to access your databases individually. These rules are created per database and stored in the database itself including master database.

These scripts should be run in the database itself and syntax is almost the same with Server-Level Firewall Rules.


-- view database-level firewall settings
select * from sys.database_firewall_rules

-- create new database-level firewall setting for only IP
exec sp_set_database_firewall_rule N'SingleIPDBFW','',''

-- update database-level firewall setting to also allow IP
exec sp_set_database_firewall_rule N'SingleIPDBFW','',''

-- Remove database-level firewall setting
exec sp_delete_database_firewall_rule N'SingleIPDBFW'



Start using your free Windows Azure trial Windows Azure Free Trial

Comments (0)

Skip to main content