Django 和 django-pyodbc 错误 NotImplementedError SQL Server v8 is not supported
Django and django-pyodbc error NotImplementedError SQL Server v8 is not supported
我正在使用 Django 和 PyODBC 连接到 SQL Server 2000 数据库,但我遇到了这个错误:
异常类型: NotImplementedError
异常值: SQL 不支持服务器 v8。
我的回溯:
Environment:
Request Method: POST
Request URL: http://localhost/sistemas/cadastro_paciente/
Django Version: 1.10.5
Python Version: 2.7.12
Installed Applications:
['admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cadastro',
'fenotipo',
'cuser']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'cuser.middleware.CuserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/var/www/sistemas/cadastro/views.py" in cadastro_paciente
1297. if pacienteDB and pacienteHGP:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __nonzero__
264. return type(self).__bool__(self)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __bool__
260. self._fetch_all()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _fetch_all
1087. self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __iter__
54. results = compiler.execute_sql()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in execute_sql
824. sql, params = self.as_sql()
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/compiler.py" in as_sql
82. supports_offset_clause = self.connection.sql_server_version >= 2012
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in __get__
35. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/base.py" in sql_server_version
390. with self.temporary_connection() as cursor:
File "/usr/lib/python2.7/contextlib.py" in __enter__
17. return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in temporary_connection
564. cursor = self.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in cursor
231. cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in _cursor
204. self.ensure_connection()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in ensure_connection
199. self.connect()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in connect
173. self.init_connection_state()
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/base.py" in init_connection_state
349. if self.sql_server_version < 2008:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in __get__
35. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/base.py" in sql_server_version
395. raise NotImplementedError('SQL Server v%d is not supported.' % ver)
Exception Type: NotImplementedError at /cadastro_paciente/
Exception Value: SQL Server v8 is not supported.
我的odbc.ini:
[HGP]
Driver = FREETDS
Server = "IP"
Port = 1433
Database = database
Driver = /usr/local/lib/libtdsodbc.so
UsageCount = 1
我的freetds.conf
[HGP]
database = database
host = "IP"
port = 1433
tds version = 8.0
odbcinst.int
上的驱动程序配置
[FREETDS]
Description = FreeTDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount = 1
我的settings.py
'hgp': {
'ENGINE': 'sql_server.pyodbc', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'hemovida', # Or path to database file if using sqlite3.
'USER': 'sa', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': 'IP', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '',
'OPTIONS': {
'driver': 'FREETDS',
'MARS_Connection': False,
'dsn' : 'HGP',
},
},
我的查询
pacienteHGP = Paciente_Hemovida.objects.using('hgp').filter(paciente=postPaciente)
如前所述,使用 SQL Server 2000 是一个 真的 坏主意;它没有收到任何支持、错误修复,或者最重要的是,来自 Microsoft 的安全补丁。
就是说,如果您使用的是 django-pyodbc-azure
,您也许可以对其进行猴子修补以使其正常工作。看到这一行:
https://github.com/michiya/django-pyodbc-azure/blob/azure-1.10/sql_server/pyodbc/base.py#L145
将 8: 2000,
添加到 _sql_server_version
词典中:
_sql_server_versions = {
8: 2000,
9: 2005,
10: 2008,
11: 2012,
12: 2014,
13: 2016,
14: 2017,
}
我无法保证这是否有效,但欢迎您尝试。这应该可以帮助您克服遇到的错误。
您还需要修改 freetds.conf
,因为 8.0
不是有效的 TDS 版本:
[HGP]
database = database
host = "IP"
port = 1433
tds version = 7.1
来源:http://www.freetds.org/userguide/choosingtdsprotocol.htm
祝你好运,我再次强烈建议升级到现代版本的 SQL 服务器。
我正在使用 Django 和 PyODBC 连接到 SQL Server 2000 数据库,但我遇到了这个错误:
异常类型: NotImplementedError
异常值: SQL 不支持服务器 v8。
我的回溯:
Environment:
Request Method: POST
Request URL: http://localhost/sistemas/cadastro_paciente/
Django Version: 1.10.5
Python Version: 2.7.12
Installed Applications:
['admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cadastro',
'fenotipo',
'cuser']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'cuser.middleware.CuserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/var/www/sistemas/cadastro/views.py" in cadastro_paciente
1297. if pacienteDB and pacienteHGP:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __nonzero__
264. return type(self).__bool__(self)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __bool__
260. self._fetch_all()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _fetch_all
1087. self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __iter__
54. results = compiler.execute_sql()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in execute_sql
824. sql, params = self.as_sql()
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/compiler.py" in as_sql
82. supports_offset_clause = self.connection.sql_server_version >= 2012
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in __get__
35. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/base.py" in sql_server_version
390. with self.temporary_connection() as cursor:
File "/usr/lib/python2.7/contextlib.py" in __enter__
17. return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in temporary_connection
564. cursor = self.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in cursor
231. cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in _cursor
204. self.ensure_connection()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in ensure_connection
199. self.connect()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in connect
173. self.init_connection_state()
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/base.py" in init_connection_state
349. if self.sql_server_version < 2008:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in __get__
35. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/base.py" in sql_server_version
395. raise NotImplementedError('SQL Server v%d is not supported.' % ver)
Exception Type: NotImplementedError at /cadastro_paciente/
Exception Value: SQL Server v8 is not supported.
我的odbc.ini:
[HGP]
Driver = FREETDS
Server = "IP"
Port = 1433
Database = database
Driver = /usr/local/lib/libtdsodbc.so
UsageCount = 1
我的freetds.conf
[HGP]
database = database
host = "IP"
port = 1433
tds version = 8.0
odbcinst.int
上的驱动程序配置[FREETDS]
Description = FreeTDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount = 1
我的settings.py
'hgp': {
'ENGINE': 'sql_server.pyodbc', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'hemovida', # Or path to database file if using sqlite3.
'USER': 'sa', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': 'IP', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '',
'OPTIONS': {
'driver': 'FREETDS',
'MARS_Connection': False,
'dsn' : 'HGP',
},
},
我的查询
pacienteHGP = Paciente_Hemovida.objects.using('hgp').filter(paciente=postPaciente)
如前所述,使用 SQL Server 2000 是一个 真的 坏主意;它没有收到任何支持、错误修复,或者最重要的是,来自 Microsoft 的安全补丁。
就是说,如果您使用的是 django-pyodbc-azure
,您也许可以对其进行猴子修补以使其正常工作。看到这一行:
https://github.com/michiya/django-pyodbc-azure/blob/azure-1.10/sql_server/pyodbc/base.py#L145
将 8: 2000,
添加到 _sql_server_version
词典中:
_sql_server_versions = {
8: 2000,
9: 2005,
10: 2008,
11: 2012,
12: 2014,
13: 2016,
14: 2017,
}
我无法保证这是否有效,但欢迎您尝试。这应该可以帮助您克服遇到的错误。
您还需要修改 freetds.conf
,因为 8.0
不是有效的 TDS 版本:
[HGP]
database = database
host = "IP"
port = 1433
tds version = 7.1
来源:http://www.freetds.org/userguide/choosingtdsprotocol.htm
祝你好运,我再次强烈建议升级到现代版本的 SQL 服务器。