How to: Configure the Server-Level Firewall Settings (Windows Azure SQL Database)
The Microsoft Windows Azure SQL Database service prevents access to your SQL Database server with the SQL Database firewall. You can use the Windows Azure Platform Management Portal or master database to review and edit your server-level firewall configuration. This topic describes how you can define server-level firewall settings to specify which clients should have access to your SQL Database server. For more information about the server-level firewall rules, see Windows Azure SQL Database Firewall.
You can also perform operations on server-level firewall rules by using the Windows Azure SQL Database API. For more information, see Operations on Server-Level Firewall Rules.
Note |
|---|
| To connect to your SQL Database server for the first time, you must enable connectivity through the firewall using the Management Portal. |
In This Topic
-
Configure Server-Level Firewall Settings Using the Management Portal
-
Configure Server-Level Firewall Settings Using the Master Database
Configure Server-Level Firewall Settings Using the Management Portal
-
Log on to the Windows Azure Management Portal.
-
In the navigation pane on the left, expand your subscription, and then select your SQL Database server by clicking it.
-
In the center pane, view the server-level firewall settings for the selected SQL Database server by clicking Firewall Rules.
-
To configure the server-level firewall settings:
-
Enable connection attempts from Windows Azure by selecting the Allow other Windows Azure services to access to this server check box. This will add a firewall rule, MicrosoftServices, with the start and end IP range values set to 0.0.0.0.
-
Add a new server-level firewall setting for Internet-based connections by clicking Add. In the Add Firewall Rule dialog box, specify a unique name in the Rule Name box with the corresponding IP address range in the IP range start and IP range end boxes. Click OK.
-
Update an existing server-level firewall setting for Internet-based connections by selecting the appropriate record and clicking Update. In the Update Firewall Rule dialog box, specify the new IP address range values in the IP range start and IP range end boxes, and click OK.
-
Enable connection attempts from Windows Azure by selecting the Allow other Windows Azure services to access to this server check box. This will add a firewall rule, MicrosoftServices, with the start and end IP range values set to 0.0.0.0.
-
Remove an existing server-level firewall setting by selecting the appropriate rule, and then clicking Delete.
Note |
|---|
| If you are using the new Windows Azure Management Portal, see How to: Configure the firewall for the logical server for instructions on configuring the server-level firewall settings. |
Configure Server-Level Firewall Settings Using the Master Database
-
Use the Management Portal to confirm that there is a firewall setting allowing your computer to attempt connection to the SQL Database server. The IP address of your computer must be within the IP address range of one of the firewall settings. For more information, see Windows Azure SQL Database Firewall.
-
Connect to the master database of the SQL Database server using your server-level principal login.
-
View the server-level firewall settings corresponding to your SQL Database server by executing the query:
select * from sys.firewall_rules -
Configure the server-level firewall settings by using the
sp_set_firewall_rulestored procedure.-
Enable connection attempts from Windows Azure by using the
sp_set_firewall_rulestored procedure with the parametersstart_ip_addressandend_ip_addressequal to0.0.0.0. -
Add a new firewall setting for Internet-based connections by specifying a unique name in the
nameparameter of thesp_set_firewall_rulestored procedure. Specify the lowest desired IP address in that range with thestart_ip_addressparameter and the highest desired IP address in that range with theend_ip_addressparameter. Thenameparameter is of the nvarchar data type and thestart_ip_addressand theend_ip_addressparameters are of the varchar data type. -
Update an existing firewall setting for Internet-based connections by specifying an existing name in the
nameparameter of thesp_set_firewall_rulestored procedure. Specify the new IP address range with thestart_ip_addressandend_ip_addressparameters.
-
Enable connection attempts from Windows Azure by using the
-
Remove a firewall setting by specifying name of the undesired firewall setting in the
nameparameter of thesp_delete_firewall_rulestored procedure.
Example
This example demonstrates how to configure your firewall settings with Transact-SQL. First, you must use the Management Portal to allow access for your computer's IP address. Then you can view the firewall settings with the following code.
-- view firewall settings select * from sys.firewall_rules
Note |
|---|
| Only the server-level principal login, while connected to the master database, can configure firewall settings for your SQL Database server. |
You can use the sp_set_firewall_rule stored procedure to add or change firewall settings. When you add a firewall setting where the beginning and ending IP addresses are equal to 0.0.0.0, you enable access to your SQL Database server from Windows Azure. Provide a value to the name parameter that will help you remember what the firewall setting is for. The following code creates a firewall setting called Allow Windows Azure that enables access from Windows Azure.
-- enable Windows Azure connections exec sp_set_firewall_rule N'Allow Windows Azure','0.0.0.0','0.0.0.0'
The following code creates a firewall setting called Example setting 1 for only the IP address 0.0.0.2. Then, the sp_set_firewall_rule stored procedure is called again to allow an additional IP address, 0.0.0.3, in that firewall setting.
-- create new 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 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'
To remove a firewall setting, use the sp_delete_firewall_rule stored procedure, as shown in the following code.
-- Remove example firewall setting exec sp_delete_firewall_rule N'Example setting 1'
See Also
Tasks
How to: Configure the Database-Level Firewall Settings (Windows Azure SQL Database)Concepts
Operations on Server-Level Firewall RulesWindows Azure SQL Database Firewall
Guidelines for Connecting to Windows Azure SQL Database
Managing Databases and Logins in Windows Azure SQL Database
Administration: How-to Topics (Windows Azure SQL Database)
Note