Establishing connection to MS SQL Server 2014 with django-mssql-1.6

纵然是瞬间 提交于 2019-12-03 16:35:50

As far as I can see, you are using the correct versions of django-mssql and Django. I recently moved from 1.6 to 1.7 and had to change the DB backend since sql_server.pyodbc is no longer supported by django 1.7. I came across this issue when changing to django-mssql (sqlserver_ado). The problem is you are using the wrong provider. Django-mssql uses SQLCLI10 as the default provider, which also did not work for me. Adding an option hash to your DB config, like the one in the above answer, will solve your problem as long as you use the SQLOLEDB provider. This is my config:

    DATABASES = {
    'default': {
        'NAME': 'CVH_Dev',
        'ENGINE': 'sqlserver_ado',
        'HOST': '192.***.212.2**',
        'USER': 'USER',
        'PASSWORD': 'PWD',
        'OPTIONS': {
            'provider': 'SQLOLEDB',
            'use_legacy_date_fields': 'True'
        }
    }
}

Use the SQLOLEDB provider option and it will work. Hope this helps.

Maybe too late, but... If you're using Django 1.10 and you don't need to stick to django-mssql, you could switch to the django-pyodbc-azure package, which supports MS SQL Server 2014 and 2016 out of the box.

Just tried out, and it works, in this environment:

  • Windows Server 2012 R2
  • Python 3.5.2
  • SQL Server 2016
  • Django 1.10

Please ensure that you are using Django 1.6 and django-mssql is 1.6 version. I've noticed that django-mssql 1.6 does not work with the latest Django 1.8.

Here are my DB config settings which has worked for me -

  DATABASES = {
      'default': {
          'ENGINE': 'sqlserver_ado',
          'NAME': 'dbname',                      # Or path to database file       if using sqlite3.
          # The following settings are not used with sqlite3:
          'USER': 'db_user_id',
          'PASSWORD': 'db_password',
          'HOST': 'host_name_or_ip_addr',                      # Empty for       localhost through domain sockets or '127.0.0.1' for localhost through TCP.
          'PORT': '1433',                      # Set to empty string for       default.
          'OPTIONS': {
                'provider' : 'SQLOLEDB'             # or these other two dlls did not work for me SQLCLI10, SQLCLI11
          },
      },
  }

Solved for me using 'SQLNCLI11' provider:

DATABASES = {
    'default': {
        'NAME': 'MyDatabase',
        'ENGINE': 'sqlserver_ado',
        'HOST': '.\\SQLEXPRESS',
        'USER': '',
        'PASSWORD': '',
        'OPTIONS': {
            'provider': 'SQLNCLI11',
            'use_legacy_date_fields': 'True'
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!