djangodjango-modelsdjango-rest-frameworkdjango-databasedjango-database-functions

while connecting to MicrosoftSQL server using Django facing django.db.utils.OperationalError:


drivers available with me
**python shell** 
    '''In [2]: pyodbc.drivers()'''
**Output:**
    **Out[2]: ['SQL Server']**

code in settings.py django:


    **Settings.py in django**

    '''# Database
    # https://docs.djangoproject.com/en/2.2/ref/settings/#databases

    DATABASES = {
        'default': {
            'ENGINE': 'sql_server.pyodbc',
            'NAME': 'dbname',
            'HOST': 'ansqlserver.database.windows.net',
            'USER': 'test',
            'PASSWORD': 'Password',

            'OPTIONS': {
                'driver': 'SQL Server',
            }
        }'''





 **ERROR:**
    **Trying to connect to MicrsoftSQL server facing below error**

File "C:\Local\Programs\Python\Python37\lib\site-packages\sql_server\pyodbc\base.py", line 314, in get_new_connectiontimeout=timeout) django.db.utils.OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver]Neither DSNnor SERVER keyword supplied (0) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute (0)')


Solution

  • Initally I have only one driver: 'SQL Server'

    later I installed different drivers

    Just enter command and see the drivers in your machine '''pyodbc.drivers()'''

    Output: ['SQL Server', 'ODBC Driver 17 for SQL Server', 'ODBC Driver 13 for SQL Server']

    after that I am able to connect to MicrosoftSQL DB without any issues