1
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)')

2 Answers2

0

Check if your database host "ansqlserver.database.windows.net" has permission to allow application server to connect.

  • hi rajeev I have permission, when i connect when I use pyodbc and python code to connect it is working fine, but not working in django – harsha Machine_learning Jun 16 '20 at 09:02
  • I think there is an issue with Database settings. Try changing "options", use this link for [mssql](https://pypi.org/project/django-mssql-backend/) – rajeev dodda Jun 16 '20 at 09:26
  • 1
    no rajeev issue is with the drivers initially I don't have any drivers other that 'SQL Server' now installed different drivers this solved the issue, thanks – harsha Machine_learning Jun 16 '20 at 11:40
0

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