自适应服务器不可用或不存在

发布于 2025-01-29 01:48:34 字数 2428 浏览 3 评论 0原文

我正在尝试通过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 指南我安装了freetdsubuntu 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 ServerODBC驱动程序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 message
pyodbc.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗喜 2025-02-05 01:48:34

正如您注意到的那样,将端口设置为1433 - 但这只是您需要做的事情的一部分。

tds_version = 8.0是无效的, 在较新版本的freetds上大于1.3: https://www.freetds.org/userguide/choosingstdsprotococol.html

自从Ubuntu 18次带有Freetds版本1.00.82的船只以来您正在使用SQL Server 2012或更高版本。

更改您的选项如下:

'OPTIONS': {
    'driver': 'FreeTDS', 
    'host_is_server': True,
    'extra_params': "TDS_Version=7.4"
},

您可能必须重新运行迁移(如果有),因为较新的TDS版本支持更多的SQL Server字段,例如date and datetime2 -但是看来您可能只是在使用SQL Server进行读取。祝你好运!

As you noticed, set the PORT to 1433 - 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.html

Since 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:

'OPTIONS': {
    'driver': 'FreeTDS', 
    'host_is_server': True,
    'extra_params': "TDS_Version=7.4"
},

You may have to re-run your migrations, if any, because the newer TDS Versions support more SQL Server fields, such as DATE and DATETIME2 - but it looks like you may just be using SQL Server for reads. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文