'Connecting to MSSQL with Django - one is working, one not

I am using PyCharm and Django to build up a accounting software. There fore, I would like to connect to an external server with MSSQL.

I am using the following settings.py

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    },

    'bnt': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'POS',
        'USER': 'l.bamberg',
        'PASSWORD': '*******',
        'HOST': '10.171.215.1',  # BNTS20005\\SQL17STD
        'PORT': '1433',

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

If I type in:

python manage.py check --database bnt

I get:

Traceback (most recent call last):
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 230, in ensure_connection
    self.connect()
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 25, in inner
    return func(*args, **kwargs)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 211, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.8/site-packages/sql_server/pyodbc/base.py", line 312, in get_new_connection
    conn = Database.connect(connstr,
pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection (0) (SQLDriverConnect)')

However, if I use View | Tool Windows | Database in Pycharm and set up a connection with the same credentials. I can see the databases.

Screenshot of Database
Screenshot of Database Properties

Any Idea. Should I switch the driver or what am I doing wrong?

Regards Georg



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source