I'm having issues connecting my Django app in my local machine to MySql Database in Azure? I added my IP in the Rules and am connecting with this:
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '<servername>.database.windows.net',
'PORT': '3306',
'NAME': '<database_name>',
'USER': '<admin>@<servername>',
'PASSWORD': '<cecret>',
'OPTIONS': {'ssl': {'pem': 'tls.pem'} }
},
I can connect using AzureDataStudio, but not with this configuration in django. I Nmaped my host, found a bunch of open ports but 3306
and 1433
are bound to Sql servers.
Django's runserver
shows MySQLdb._exceptions.OperationalError: (2002, "Can't connect to server on '<servername>.database.windows.net' (115)")
with this configuration even if I have that server and database within it running.
One example php
query string in Azure portal has:
$conn = new PDO("sqlsrv:server = tcp:<server_name>.database.windows.net,1433; Database = <database_name>", "<admin>", "{your_password_here}");
So, I'm assuming I should connect to 1433
but only 3306
works from DataStudio. From python manage.py runserver
it shows django.db.utils.OperationalError: (2013, "Lost connection to server at 'handshake: reading initial communication packet', system error: 104")
if I try port 1433
. I'm at the limit of my knowledge regarding this.
Correction-1: 3306
doesn't seem to work with Azure DataStudio. But using 1433
in Django settings won't even initialize connection.