Torin M.
Torin M.

Reputation: 533

Cannot establish connection to sql-server using pyodbc on Windows 10

Getting this error when trying to run development server on django.

django.db.utils.Error: ('08001', '[08001] [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53].  (53) (SQLDriverConnect)')

Here is my settings.py databases

DATABASES = {
'default': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'mydata',
    'USER': 'user@mydata',
    'PASSWORD': '**password**',
    'HOST': 'mydata.database.windows.net',
    'PORT':'**port**',

    'OPTIONS': {
        'driver': 'SQL Server',
        'host_is_server': True,
        'MultipleActiveResultSets': False,
        'Encrypt': True,
        'TrustServerCertificate': False,
        'Connection Timeout': 30,
        'Persist Security Info': False,
    },
},
}

I have django-pyodbc and django-pyodbc-azure installed.

Using django version 1.11.

Any help would be awesome! Thank you.

EDIT 1

I changed driver to SQL Sever and updated the driver. Now I am getting this error.

django.db.utils.Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect)')

I have the database set up on Azure.

Upvotes: 1

Views: 2710

Answers (1)

Peter Pan
Peter Pan

Reputation: 24138

According to your error information, there are two possible reason which caused the issue, as below.

  1. The driver option value should be ODBC Driver 13 for SQL Server as the figure below from Azure portal. Please change it and try again.

enter image description here

  1. The access denied error may be caused by not adding your client IP to the firewall of Azure SQL Database to allow access, as the figure below.

enter image description here

Hope it helps.

Upvotes: 1

Related Questions