[Answered ]-Can't connect django to exist MS SQL Server using mssql-django

1👍

Keep "PORT" blank or remove "PORT" otherwise there will be error if setting any port number e.g. "2244", "9877" or even "1433" which is the default port number of MSSQL:

DATABASES = {
    "default": {
        "ENGINE": "mssql",
        "NAME": "eHospital_DKAG_NSTL",
        "USER": "sa",
        "PASSWORD": "passwod",
        "HOST": "172.16.2.20\sqlservertest",
        "PORT": "",       # Keep it blank
        # "PORT": "1433", # Or remove it
        "OPTIONS": {
            "driver": "ODBC Driver 17 for SQL Server", 
        },
    },
}

You can see that in Example of mssql-django, "PORT" is kept blank as shown below:

DATABASES = {
    'default': {
        'ENGINE': 'mssql',
        'NAME': 'mydb',
        'USER': 'user@myserver',
        'PASSWORD': 'password',
        'HOST': 'myserver.database.windows.net',
        'PORT': '', # Kept blank

        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    },
}

# set this to False if you want to turn off pyodbc's connection pooling
DATABASE_CONNECTION_POOLING = False

Leave a comment