自适应服务器不可用或不存在
我正在尝试通过freetds
连接到MSSQL
服务器。
首先,我通过SQL Server 通过ODBC驱动程序17尝试了它,并且可以使用。这是我在
settings.py
中的配置。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'mssql_database': {
'ENGINE': 'django_pyodbc',
'NAME': 'blabla',
'USER': 'blabla',
'PASSWORD': 'blabla',
'HOST': '10.65.1.20',
'PORT': '',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
},
},
}
根据< this this 指南我安装了freetds
在ubuntu 18.04
上。
这是我的/etc/odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.9.so.1.1
UsageCount=1
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
CPTimeout =
CPReuse =
,这是新的settings.py
e节
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'mssql_database': {
'ENGINE': 'django_pyodbc',
'NAME': 'blabla',
'USER': 'blabla',
'PASSWORD': 'blabla',
'HOST': '10.65.1.20',
'PORT': '',
'OPTIONS': {
'driver': 'FreeTDS',
'host_is_server': True,
'extra_params': "TDS_VERSION=8.0"
},
},
}
,我有此错误消息 ] [SQL Server]无法连接:自适应服务器不可用或不存在(20009)(20009)(SQLDRIVERCONNECT)')
pyodbc.operationalerror :('08S01','[08S01] [08S01] [ freetds 解决错误?该连接可与SQL Server
的ODBC驱动程序17一起工作。那么,为什么它不适用于
freetds
驱动程序呢?可能是因为文件/usr/lib/x86_64-linux-gnu/odbc/libtdss.so
不存在吗?我找不到libtdss.so
。
$ pip list
Package Version
------------- -------
Django 1.8
django-pyodbc 1.1.3
pip 21.3.1
pyodbc 4.0.32
setuptools 59.6.0
sqlany-django 1.13
sqlanydb 1.0.11
wheel 0.37.1
I'm trying to connect to mssql
server via FreeTDS
.
First I tried it via ODBC Driver 17 for SQL Server
and it works. Here is my configuration in settings.py
.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'mssql_database': {
'ENGINE': 'django_pyodbc',
'NAME': 'blabla',
'USER': 'blabla',
'PASSWORD': 'blabla',
'HOST': '10.65.1.20',
'PORT': '',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
},
},
}
According to this guide I installed FreeTDS
on Ubuntu 18.04
.
Here is my /etc/odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.9.so.1.1
UsageCount=1
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
CPTimeout =
CPReuse =
And here is the new settings.py
section
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'mssql_database': {
'ENGINE': 'django_pyodbc',
'NAME': 'blabla',
'USER': 'blabla',
'PASSWORD': 'blabla',
'HOST': '10.65.1.20',
'PORT': '',
'OPTIONS': {
'driver': 'FreeTDS',
'host_is_server': True,
'extra_params': "TDS_VERSION=8.0"
},
},
}
And I have this error messagepyodbc.OperationalError: ('08S01', '[08S01] [FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist (20009) (SQLDriverConnect)')
How can I fix the error? The connection works with ODBC Driver 17 for SQL Server
. So why doesn't it work with FreeTDS
driver? Could it be because the file /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
isn't there? I can't find libtdsS.so
.
$ pip list
Package Version
------------- -------
Django 1.8
django-pyodbc 1.1.3
pip 21.3.1
pyodbc 4.0.32
setuptools 59.6.0
sqlany-django 1.13
sqlanydb 1.0.11
wheel 0.37.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您注意到的那样,将
端口
设置为1433
- 但这只是您需要做的事情的一部分。tds_version = 8.0
是无效的, 在较新版本的freetds上大于1.3: https://www.freetds.org/userguide/choosingstdsprotococol.html自从Ubuntu 18次带有Freetds版本1.00.82的船只以来您正在使用SQL Server 2012或更高版本。
更改您的选项如下:
您可能必须重新运行迁移(如果有),因为较新的TDS版本支持更多的SQL Server字段,例如
date
anddatetime2
-但是看来您可能只是在使用SQL Server进行读取。祝你好运!As you noticed, set the
PORT
to1433
- but that is only part of what you need to do.TDS_Version=8.0
is invalid and will break on newer versions of FreeTDS greater than 1.3: https://www.freetds.org/userguide/ChoosingTdsProtocol.htmlSince Ubuntu 18 ships with FreeTDS version 1.00.82, you should use version 7.4 of the TDS protocol, assuming you are using SQL Server 2012 or higher.
Change your options as follows:
You may have to re-run your migrations, if any, because the newer TDS Versions support more SQL Server fields, such as
DATE
andDATETIME2
- but it looks like you may just be using SQL Server for reads. Good luck!