1

I used Django to connect to SQL Server 2016 and I started executing Python3" manage.py Runserver 8000

Terminal prompt:

django.db.utils .InterfaceError: ('28000', "[28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'test'. (18456) (SQLDriverConnect)")”

enter image description here

I don't know where the problem is.

This is my database configuration

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME':'testDB',#db name 
        'USER':'test',#db longin user
        'PASSWORD':'test#2021',#db longin pwd
        'HOST': '10.32.9.51',#db host
        'PORT': '1433',#port,default1433
        'OPTIONS': {#odbc driver
            'provider': 'SQLOLEDB', # Have also tried 'SQLCLI11' and 'SQLOLEDB'
            'driver': 'ODBC Driver 17 for SQL Server',
            'MARS_Connection': True,
        },
    }
}

But I use pyodbc to connect to the database and query. At this time, the query is successful。

import pyodbc
try:
        conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=10.32.9.51;PORT=1433;DATABASE= testDB;UID=test;PWD=test#2021')
        cursor=conn.cursor()
        cursor.execute("select getdate()")
        row=cursor.fetchone()
        while row:
                print("sqlserver date:%s"%(row[0]))
                row=cursor.fetchone()
                print(row)
        conn.close()
except Exception as e:
    print("DB Error")
    print("DB Error:"+str(e))

enter image description here

System environment:

System:Centos 7
python: 3.7.9、
Django:2.1.15、
django-mssql:1.8、
django-pyodbc:1.1.3、
django-pyodbc-azure:2.1.0.0、
django-sqlserver:1.11、
djangorestframework:3.12.2、
pip:21.0.1、
pymssql:2.1.5、
PyMySQL:1.0.2、
pyodbc:4.0.30、

SQL Server configuration:

enter image description here

enter image description here

enter image description here

imxitiz
  • 3,920
  • 3
  • 9
  • 33
SunnyWu
  • 11
  • 2
  • probably the hashtag in the password. See https://stackoverflow.com/a/39207995/4872140 which says to do `'PASSWORD':'test%232021'` – AMG Mar 09 '21 at 02:41
  • It's a shame the State number isn't included in the error message, that makes it a lot easier to resolve the issue. [MSSQLSERVER_18456](https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-18456-database-engine-error#additional-error-information) – AlwaysLearning Mar 09 '21 at 03:13

0 Answers0