You need port TCP port 1433 but you also need to know if you are able to resolve the name of the Azure SQL logical server (xxx.database.windows.net) to an IP address. If you ping the name of the Azure SQL logical server you will see the ping will fail but it should also return the current IP address of the server, if that does not happen on your corporate network then you may have problems to connect to Azure SQL, even if you use the IP address, as the IP address changes over time.
Issues connecting to Azure SQL database - Python
Hi all! So I am having problems connecting to my Azure SQL database. I am trying to do this with python by following the instructions here:
https://learn.microsoft.com/en-us/sql/connect/python/pyodbc/step-3-proof-of-concept-connecting-to-sql-using-pyodbc?view=sql-server-ver15
My code:
The results when run:
I have installed pyodbc and confirmed that I have ODBC driver 17 installed:
I performed a trace on the azure server, which seems to suggest that the company firewall is not an issue (though would seek advice on this):
Tried pretty much every suggestion here:
https://stackoverflow.com/questions/18860620/cannot-establish-connection-to-sql-server-using-pyodbc-on-windows-7
Including defining the connection string parameters as keyword arguments:
cnxn = pyodbc.connect(driver='{ODBC Driver 17 for SQL Server}', SERVER=server, DATABASE=database, UID=username, PWD=password)
I have set the public access firewall settings for the database within the Azure Hub following the instructions here: IP firewall rules - Azure SQL Database and Azure Synapse Analytics | Microsoft Learn
My settings:
I then tried to connect to the database with Visual Studio Code from with the Azure Hub:
However, I had similar luck:
Could anyone offer me any advice on what the problem may be and how I can overcome this to connect to my Azure SQL database?
Thanks in advance!
Azure SQL Database
Azure Functions
-
Alberto Morillo 35,401 Reputation points MVP Volunteer Moderator2022-05-16T17:19:13.137+00:00
1 additional answer
Sort by: Most helpful
-
ChrisU 231 Reputation points
2022-05-16T15:19:21.623+00:00 Hi Geetha and thanks for your response. I have since investigated this further and by using a phone hotspot connection and it is now working. So it must have been a firewall issue on my companies network. Do you have any idea what ports need to be open on a firewall to allow these sorts of connections to an Azure SQL database?