This post describes how to work your way around the exception ‘Cannot open server – requested by login…’ The issue is caused by Azure’s somewhat annoying firewall logic, and might stop you from accessing your databases from your development machine.
When trying to publish a web project to Azure from Visual Studio, you suddenly get the following (or similar) error message:
“Cannot open server ‘xxx.xxx.xxx.xxx’ requested by the login. Client with IP address ‘xxx.xxx.xxx.xxx’ is not allowed to access the server. To enable access, use the SQL Azure Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.”
Your IP address has changed (for any reason) and Azure won’t allow your login anymore (as there’s a built-in IP filtering enabled). Azure kind of works as expected, Visual Studio’s error message just isn’t the most useful out there. Luckily, instead of running stored procedures or navigating the constantly evolving Azure Portal to desperately try to find a place where to edit SQL Server firewall rules, you can do this directly and conveniently in Visual Studio.
Solution 1 – using the builtin firewall prompt
You’ll need to connect to the SQL Server through Visual Studio, which will prompt you to allow access to the server for your current IP address. Like so:
And here’s the very useful dialog:
It appears that the pop-up dialog mentioned above sometimes randomly does not appear. That’ll stop you from modifying the firewall this way. In that case, there’s another way to add the firewall rule, see here.
And there you are!
You may want to remember this trick, as it’s bound to happen again when your IP address changes 🙂
(The last two images from: https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-deploy-aspnet-mvc-app-membership-oauth-sql-database/)
And what if it doesn’t work? Well – that brings us to…
Solution 2 – modifying firewall via Azure Portal
You’ll need to access the database in the management portal. The link in Visual Studio has never worked for me (shown in the picture below), but you can luckily access it via url, too.
https://portal.azure.com/#blade/SqlAzureExtension (Update 10.4.2017: This link didn’t work anymore. Working one below!)
Using this dialog, you can modify the firewall rules easily. You can add either your IP address or the whole space of your network, if you know it!
Latest posts by Antti K. Koskela (see all)
- How to fix an Office Group with no Owners - November 14, 2018
- Help! My “Content and Structure” page in SharePoint Online is gone! - November 7, 2018
- Thanks for coming to my session at SPS New England 10/20 ! - October 20, 2018
- Speaking at SPS New England on 10/20! - October 17, 2018