0
votes

I can't connect MSsql database to django.

When I trying to do with python, It works well, but when I try to run server on Django I get error.

Pyodbc version : 4.0.27; Django version : 2.1.13; Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64).

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': '<djangoBanks>',
        'HOST': '<DESKTOP-0FKB14V>',
        'USER': '<test>',
        'PASSWORD': '<12345>',

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

When I try to run python manage.py runserver I get this error:

'08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. (53) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (53)'

1

1 Answers

0
votes

I edited 'Options' and then it started work.

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'djangoBanks',
        'HOST': 'DESKTOP-0FKB14V',
        'USER': 'test',
        'PASSWORD': '12345',

    'OPTIONS': {
            'driver': "ODBC Driver 17 for SQL Server",
            'SERVER' : 'DESKTOP-0FKB14V',
            'DATABASE' : 'djangoBanks',
            'UID' : 'test',
            'PWD' : '12345',
            'Trusted_Connection' : 'Yes',
        }
    }
}