UENO Satosi - 2021-05-13

I have SQLServer 2017 instances on Windows 2016 Server installed on Oracle Virtualbox.
When I try to connect to the server by isql and FreeTDS driver with wrong user name or password, I get garbled(mojibake) error message as follows.

$ isql -v EXP sa Password
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[37000][unixODBC][FreeTDS][SQL Server]???? 'sa' ??????????????
[ISQL]ERROR: Could not SQLConnect

How can I get right error message?

I confirmed that I could connect to the server when I set right user name and password.

If the defalut language of SQLServer is English, I get right English message. But I don't
want this option because I'm doubtful my application based on the server support it.

$ isql -v EXP sa Password
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[37000][unixODBC][FreeTDS][SQL Server]Login failed for user 'sa'.
[ISQL]ERROR: Could not SQLConnect

When I use tsql command directly, I got right Japanese error message(image file attached).

$ tsql -S Exp -U sa -P Password 
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Msg 18456 (severity 14, state 1) from SQLSERVER\SQLEXPRESS Line 1:
    "ユーザー 'sa' はログインできませんでした。"
Error 20002 (severity 9):
    Adaptive Server connection failed
There was a problem connecting to the server

My environment is as follows.

Client OS: CentOS Linux release 7.6.1810 (Core)
unixODBC version: 2.3.7-1
freetds version: 0.95.81-1
locale: ja_JP.UTF-8

Server OS: Windows Server 2016 Essentials
SQL Server version:

Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) 
    Aug 22 2017 17:04:49 
    Copyright (C) 2017 Microsoft Corporation
    Express Edition (64-bit) on Windows Server 2016 Essentials 10.0 <X64> (Build 14393: )

.odbc.ini:

[EXP]
Driver          = /usr/lib64/libtdsodbc.so
Description     = Sample DSN
Trace           = Yes
Server          = 192.168.56.108
Database        = db
Port            = 1433
TDS_Version     = 8.0
Charset         = UTF-8
ClientCharset   = UTF-8

trace log(failed login case)

[ODBC][9304][1620862998.445997][SQLDisconnect.c][208]
        Entry:
            Connection = 0xa81060
[ODBC][9304][1620862998.446151][SQLDisconnect.c][379]
        Exit:[SQL_SUCCESS]
[ODBC][9304][1620862998.446185][SQLFreeHandle.c][290]
        Entry:
            Handle Type = 2
            Input Handle = 0xa81060
[ODBC][9304][1620862998.446221][SQLFreeHandle.c][339]
        Exit:[SQL_SUCCESS]
[ODBC][9304][1620862998.446234][SQLFreeHandle.c][220]
        Entry:
            Handle Type = 1
            Input Handle = 0xa80750
[ODBC][9338][1620863011.019582][__handles.c][460]
        Exit:[SQL_SUCCESS]
            Environment = 0x2372750
[ODBC][9338][1620863011.019611][SQLAllocHandle.c][377]
        Entry:
            Handle Type = 2
            Input Handle = 0x2372750
[ODBC][9338][1620863011.019626][SQLAllocHandle.c][493]
        Exit:[SQL_SUCCESS]
            Output Handle = 0x2373060
[ODBC][9338][1620863011.019641][SQLConnect.c][3721]
        Entry:
            Connection = 0x2373060
            Server Name = [EXP][length = 3 (SQL_NTS)]
            User Name = [sa][length = 2 (SQL_NTS)]
            Authentication = [********][length = 8 (SQL_NTS)]
        UNICODE Using encoding ASCII 'UTF-8' and UNICODE 'UTF16LE'

        DIAG [42000] [FreeTDS][SQL Server]???? 'sa' ??????????????

        DIAG [S1000] [FreeTDS][SQL Server]Unable to connect to data source

[ODBC][9338][1620863011.029831][SQLConnect.c][4093]
        Exit:[SQL_ERROR]
[ODBC][9338][1620863011.029849][SQLError.c][424]
        Entry:
            Connection = 0x2373060
            SQLState = 0x7ffc228c5b00
            Native = 0x7ffc228c5afc
            Message Text = 0x7ffc228c5b10
            Buffer Length = 500
            Text Len Ptr = 0x7ffc228c5afa
[ODBC][9338][1620863011.029865][SQLError.c][474]
        Exit:[SQL_SUCCESS]
            SQLState = S1000
            Native = 0x7ffc228c5afc -> 0
            Message Text = [[unixODBC][FreeTDS][SQL Server]Unable to connect to data source]
[ODBC][9338][1620863011.029890][SQLError.c][424]
        Entry:
            Connection = 0x2373060
            SQLState = 0x7ffc228c5b00
            Native = 0x7ffc228c5afc
            Message Text = 0x7ffc228c5b10
            Buffer Length = 500
            Text Len Ptr = 0x7ffc228c5afa
[ODBC][9338][1620863011.029904][SQLError.c][474]
        Exit:[SQL_SUCCESS]
            SQLState = 37000
            Native = 0x7ffc228c5afc -> 18456
            Message Text = [[unixODBC][FreeTDS][SQL Server]???? 'sa' ??????????????]
[ODBC][9338][1620863011.029919][SQLError.c][424]
        Entry:
            Connection = 0x2373060
            SQLState = 0x7ffc228c5b00
            Native = 0x7ffc228c5afc
            Message Text = 0x7ffc228c5b10
            Buffer Length = 500
            Text Len Ptr = 0x7ffc228c5afa
[ODBC][9338][1620863011.029930][SQLError.c][474]
        Exit:[SQL_NO_DATA]
[ODBC][9338][1620863011.029942][SQLError.c][424]
        Entry:
            Environment = 0x2372750
            SQLState = 0x7ffc228c5b00
            Native = 0x7ffc228c5afc
            Message Text = 0x7ffc228c5b10
            Buffer Length = 500
            Text Len Ptr = 0x7ffc228c5afa
[ODBC][9338][1620863011.029953][SQLError.c][474]
        Exit:[SQL_NO_DATA]
[ODBC][9338][1620863011.029970][SQLFreeHandle.c][290]
        Entry:
            Handle Type = 2
            Input Handle = 0x2373060
[ODBC][9338][1620863011.029984][SQLFreeHandle.c][339]
        Exit:[SQL_SUCCESS]
[ODBC][9338][1620863011.030009][SQLFreeHandle.c][220]
        Entry:
            Handle Type = 1
            Input Handle = 0x2372750

trace log(successful login case)

[ODBC][9304][1620862921.196029][__handles.c][460]
        Exit:[SQL_SUCCESS]
            Environment = 0xa80750
[ODBC][9304][1620862921.196067][SQLAllocHandle.c][377]
        Entry:
            Handle Type = 2
            Input Handle = 0xa80750
[ODBC][9304][1620862921.196084][SQLAllocHandle.c][493]
        Exit:[SQL_SUCCESS]
            Output Handle = 0xa81060
[ODBC][9304][1620862921.196100][SQLConnect.c][3721]
        Entry:
            Connection = 0xa81060
            Server Name = [EXP][length = 3 (SQL_NTS)]
            User Name = [sa][length = 2 (SQL_NTS)]
            Authentication = [*********][length = 9 (SQL_NTS)]
        UNICODE Using encoding ASCII 'UTF-8' and UNICODE 'UTF16LE'

[ODBC][9304][1620862921.320656][SQLConnect.c][4299]
        Exit:[SQL_SUCCESS]
[ODBC][9304][1620862921.320691][SQLGetFunctions.c][151]
        Entry:
            Connection = 0xa81060
            Id = SQLMoreResults
            Supported = 0x606400
[ODBC][9304][1620862921.320704][SQLGetFunctions.c][209]
        Exit:[SQL_SUCCESS]
            Supported = 0x606400 -> 1