无法从DJango和Python的当前版本连接到SQL Server 2012 [英] Not able to connect to SQL Server 2012 from current version of DJango and Python

查看:27
本文介绍了无法从DJango和Python的当前版本连接到SQL Server 2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Pyodbc Django 框架连接到 SQL Server 2012 .

I am trying to connect to SQL server 2012 using Pyodbc and Django framework.

但是 Django 的版本是 2.1 .现在,当我仅安装 Pyodbc 时尝试使用以下代码进行连接时,以下代码将无法运行.

But the version of Django is 2.1. Now, when I try to connect using below code when I only have Pyodbc installed then the below code doesnot run.

DATABASES = {
    'default': {
        # 'ENGINE': '{ODBC Driver 11 for SQL Server}', Tried this as well but it did not work.
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'MY_DATABASE',
        # 'HOST': 'XXX.XX.XXX.XXX', Tried this as well but it did not work.
        'SERVER': 'XXX.XX.XXX.XXX',
        # 'HOST': 'SQLSERVER_InstanceName',
        'PORT': '',
        'USER': 'SQLSERVERUSER',
        'PASSWORD': 'USERs PASSWORD',
        'DATABASE': 'MY_DATABASE',
        # 'Trusted_Connection': 'Yes',
        # 'OPTIONS': {
        #             'driver': 'ODBC Driver 11 for SQL Server',
        #            }
    },
}

但是,当我安装 django-pyodbc-azure 并尝试通过运行 python manage.py inspectdb 命令运行上述代码时,它可以工作.但是使用 django-pyodbc-azure 的问题是它将 django 的当前版本降级为 2.0.8 -我不希望这样做

But when I install django-pyodbc-azure and try to run the above code by running python manage.py inspectdb command, it works. But the problem with using django-pyodbc-azure is that it downgrades the current version of django to 2.0.8 - which I do not want.

我不想使用 FreeTDS Pymssql ;我只想使用 pyodbc .

I do not want to use FreeTDS or Pymssql; I want to go with pyodbc only.

有人可以提出一些建议吗?

Can someone please suggest some way for this?

推荐答案

到目前为止,django-pyodbc-azure支持Django 2.1.下面是我的配置.

As of today, django-pyodbc-azure supports Django 2.1. Below is my configuration.

这是我用来配置连接的代码.

And here is the code that I used to configure the connection.

DATABASES = {
'default': {
    'ENGINE': "sql_server.pyodbc",
    'HOST': "server_name",
    'USER': "username",
    'PASSWORD': "password",
    'NAME': "database_name",
    'OPTIONS' : {
        'driver': 'ODBC Driver 13 for SQL Server',
    },
  }
}

注意:请勿将服务器的IP地址用作主机,而应使用计算机名称.

Note: Don't use the IP address of the server as the HOST, instead use the computer name.

这篇关于无法从DJango和Python的当前版本连接到SQL Server 2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆