0

I have been trying to link my mssql database to Django. When I run the Django server I get the error below. For normal query (out of Django), it works fine, however, the Django doesnt even connect. The weird thing is that when I change the driver to 'SQL SERVER' instead of 'ODBC Driver 17 for SQL Server'. I get no error. However, I need 'ODBC Driver 17 for SQL Server' because it has a lot of features that I need.

File "C:\ProgramData\Anaconda3\lib\site-packages\sql_server\pyodbc\base.py", line 307, in get_new_connection
    timeout=timeout)
django.db.utils.InterfaceError: ('28000', "[28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'EMEA\\kmoh'. (18456) (SQLDriverConnect); [28000] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0); [28000]
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'EMEA\\kmoh'. (18456); [28000] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0)")
  • Windows 10
  • django-pyodbc-azure: version 2.1
  • Django 2.1
  • Pyodbc: 4.0.25

my Django settings.py looks like this:

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'HOST': 'xxx', #has been hide for this post
        'PORT': '1433',
        'NAME': 'BBL_Result',
        #'ODBC_DSN': 'BBL'
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            'extra_params': "Persist Security Info=FALSE;server=xxx", #has been hide for this post

        },
    },
}
  • Why is server=xxx in extra params? Surely the connection string already has information from HOST? Is there a facility here to have the connection string printed out for debug purposes? Hard for us to determine exactly what is wrong when the error is about a connection string we can't see. – Aaron Bertrand Apr 17 at 11:29
  • Could you please take a look at this: stackoverflow.com/a/54145236/7895818 – Kashan Apr 17 at 12:04
  • ? That seems to have solved that problem for someone else, but has caused you a different problem. Seems all the other things are upper case, did you try SERVER instead of server? – Aaron Bertrand Apr 17 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.