Facing Issue with ODBC Driver 17 for SQL Server

1,651 views
Skip to first unread message

Sahan Srinivas

unread,
Feb 10, 2023, 5:26:00 PM2/10/23
to Django users
Hi All,

I am facing an issue with the DJANGO SQL Driver below is the screenshot, It is showing the error as 

django.db.utils.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.\r\n (10061) (SQLDriverConnect)

Below are my Database details in settings.py file.

DATABASES ={
    'default':{
    'ENGINE':"sql_server.pyodbc",
    'NAME':"IRIS",
    'USER':"sa",
    'PASSWORD':'admin123#',
    'HOST':'Pegasus\MSSQLSERVER2022',
    'PORT':'1433',
    'OPTIONS':{
    'driver':'ODBC Driver 17 for SQL Server',
    },
  },
}

Can anyone help me out? The driver's are installed, the same I can run using SQL alchemy

Kind Regards,
Sahan


DJANGO_Driver.jpg

David Nugent

unread,
Feb 10, 2023, 7:28:39 PM2/10/23
to Django users
Hi Sahan,

"the target machine actively refused it” - in TCP parlance, that means that there’s nothing listening on that port, aka connection refused”. The server you are trying to connect to isn’t there (or there is a firewall similar blocking the connection - but doubt it).

IIRC by default SQL Server runs each instance on its own port, and uses a broker (aka “browser service”) to determine which instance you are connecting to (on port 1434?). See this link for more info:


Again, from memory (which may not be accurate), each instance may have a “dynamic port” allocated but will consistently expose itself on the same port each time it is started. So locking in a particular port in Django is normally ok. You just need to determine what port that is. :-)

The db connector in Django knows or understands the dynamic connection strategy that SQL Server uses, but needs the port number directly assigned to the instance..

HTH,
/d


------ Original Message ------
From "Sahan Srinivas" <26s...@gmail.com>
To "Django users" <django...@googlegroups.com>
Date 2/11/2023 3:48:49 AM
Subject Facing Issue with ODBC Driver 17 for SQL Server

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/208fbabc-c1c9-4770-8428-0679927a6005n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages