[08001][Microsoft][SQL Server 的 ODBC 驱动程序 18]TCP 提供程序:错误代码 0x2746 - Ubuntu 22.04

[08001][Microsoft][SQL Server 的 ODBC 驱动程序 18]TCP 提供程序:错误代码 0x2746 - Ubuntu 22.04

我正在尝试从我的 ubuntu 服务器 22.04 连接到 MS SQL Server 2016。

我按照 MS 官方文档安装了 odbc 驱动程序:https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver16

安装工作正常,我可以连接到较新的 MS SQL 服务器,问题是连接到 2016 SQL Server,看起来像是 OpenSSL 版本的问题。Ubuntu 22.04 默认使用 openssl 3.xx

我通过添加到 /etc/odbcinst.ini 启用了一些调试选项

[ODBC]
Trace = Yes
TraceFile = /dev/stdout

而且输出没有多大帮助。我找到了一些解决方案,但总是与旧的 ubuntu 有关。

输出如下:

[ODBC][62430][1664301799.879691][__handles.c][460]
        Exit:[SQL_SUCCESS]
            Environment = 0x55b6b35d3870
[ODBC][62430][1664301799.879839][SQLAllocHandle.c][377]
        Entry:
            Handle Type = 2
            Input Handle = 0x55b6b35d3870
        UNICODE Using encoding ASCII 'UTF-8' and UNICODE 'UCS-2LE'

[ODBC][62430][1664301799.880405][SQLAllocHandle.c][513]
        Exit:[SQL_SUCCESS]
            Output Handle = 0x55b6b35d4590
[ODBC][62430][1664301799.880465][SQLDriverConnect.c][748]
        Entry:
            Connection = 0x55b6b35d4590
            Window Hdl = (nil)
            Str In = [Driver={ODBC Driver 18 for SQL Server};Server=tcp:xxxx,1433;Database=xxx;UID=xxx;PWD=**********;][length = 116 (SQL_NTS)]
            Str Out = 0x7fffe858da30
            Str Out Max = 2048
            Str Out Ptr = (nil)
            Completion = 0
[ODBC][62430][1664301799.903128][__handles.c][460]
        Exit:[SQL_SUCCESS]
            Environment = 0x55b6b370ad10
[ODBC][62430][1664301799.903245][SQLGetEnvAttr.c][157]
        Entry:
            Environment = 0x55b6b370ad10
            Attribute = 65002
            Value = 0x7fffe8586090
            Buffer Len = 128
            StrLen = 0x7fffe858602c
[ODBC][62430][1664301799.903298][SQLGetEnvAttr.c][273]
        Exit:[SQL_SUCCESS]
[ODBC][62430][1664301799.903319][SQLFreeHandle.c][220]
        Entry:
            Handle Type = 1
            Input Handle = 0x55b6b370ad10
        DIAG [08001] [Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Error code 0x2746

        DIAG [08001] [Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection

[ODBC][62430][1664301799.903893][SQLDriverConnect.c][1637]
        Exit:[SQL_ERROR]
[ODBC][62430][1664301799.903976][SQLError.c][424]
        Entry:
            Connection = 0x55b6b35d4590
            SQLState = 0x7fffe858f046
            Native = 0x7fffe858f040
            Message Text = 0x7fffe858f050
            Buffer Length = 500
            Text Len Ptr = 0x7fffe858f03e
 [08001][Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Error code 0x2746
[08001][Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection

另外,我已经安装了 OpenSSL 1.0.1k 并手动编译了代码,但是从 isql 或 sqlcmd 查看 strace 时,它​​仍然使用 openssl 3,您可以在此处看到:

openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libcrypto.so.3", O_RDONLY|O_CLOEXEC) = 4
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libssl.so.3", O_RDONLY|O_CLOEXEC) = 4

您知道如何从 odbc 驱动器更改 libssl 吗?

相关内容