Search code examples
visual-studioazureconnectionazure-sql-database

Can't access Azure SQL database with Visual Studio but can with SSMS


I'm trying to connect to an SQL database hosted on Azure from a function app I'm building in Visual Studio but I'm getting the following error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - An attempt was made to access a socket in a way forbidden by its access permissions.)

I can connect from the same PC using SSMS without a problem. I've tried connecting to the database using data connections in server explorer in VS but I'm getting the same error. If I connect to Azure with my account in server explorer it shows me a selection of services including SQL databases but there are none listed underneath although my account does have access to the database.

Are there any hidden gotchas I'm missing or settings within VS? I've also tried adding my client IP in the firewall settings but that didn't make a difference either.


Solution

  • After doing some more testing it turned out to be the client firewall that was blocking VS and VS Code from connecting to Azure SQL. It seems there was already an exception for SSMS.