Sql server 无法使用FreeTDS从Linux VM连接到MSSQL服务器

Sql server 无法使用FreeTDS从Linux VM连接到MSSQL服务器,sql-server,tsql,windows-authentication,freetds,unixodbc,Sql Server,Tsql,Windows Authentication,Freetds,Unixodbc,我已经在RHEL VM上设置了FreeTDS+UnixODBC,并且有一个使用Windows Auth作为默认值的MS SQL Server 我正在尝试使用windows身份验证连接到此MS SQL server 以下是我的freeTDS和ODBC配置文件 freetds.conf [global] tds version = 7.2 dump file = /tmp/freetds.log debug flags = 0xffff

我已经在RHEL VM上设置了FreeTDS+UnixODBC,并且有一个使用Windows Auth作为默认值的MS SQL Server

我正在尝试使用windows身份验证连接到此MS SQL server

以下是我的freeTDS和ODBC配置文件

freetds.conf

[global]
        tds version = 7.2
        dump file = /tmp/freetds.log
        debug flags = 0xffff
        timeout = 10
        connect timeout = 10
        text size = 64512

[mssql_db1_freetds]
    host = {ip}
    port = 1433
    timeout = 600
    connect timeout = 600
    tds version = 7.2
    text size = 20971520
odbc.ini

[mssql_db1_freetds]
Description             = MSSQL Server
Driver                  = freetds
Database                = {DB_Name}
ServerName              = mssql_db1_freetds
TDS_Version             = 7.2
Trace = Yes
TraceFile       = /tmp/mstest.log
[FreeTDS]
Description=v0.91 with protocol v7.2
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
UsageCount=1
FileUsage=1
odbcinst.ini

[mssql_db1_freetds]
Description             = MSSQL Server
Driver                  = freetds
Database                = {DB_Name}
ServerName              = mssql_db1_freetds
TDS_Version             = 7.2
Trace = Yes
TraceFile       = /tmp/mstest.log
[FreeTDS]
Description=v0.91 with protocol v7.2
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
UsageCount=1
FileUsage=1
我正在使用它通过tsql传递我的windows身份验证:

/usr/bin/tsql -S {ip} -U "{domain}\{username}" -I /etc/freetds/freetds.conf
我得到以下错误:

locale is "C"
locale charset is "ANSI_X3.4-1968"
using default charset "ISO-8859-1"
Error 100 (severity 11):
        unrecognized msgno
Msg 18452 (severity 14, state 1) from {Server_Name} Line 1:
        "Login failed. The login is from an untrusted domain and cannot be used with Windows authentication."
Error 20002 (severity 9):
        Adaptive Server connection failed
There was a problem connecting to the server
这是我的freetds日志:

09:03:25.326729 25546 (log.c:196):Starting log file for FreeTDS 0.91
        on 2019-08-26 09:03:25 with debug flags 0xffff.
09:03:25.326925 25546 (util.c:331):tdserror(0x239dbb0, 0x239dcd0, 100, 0)
09:03:25.326961 25546 (util.c:361):tdserror: client library returned TDS_INT_CANCEL(2)
09:03:25.326966 25546 (util.c:384):tdserror: returning TDS_INT_CANCEL(2)
09:03:25.326972 25546 (iconv.c:330):tds_iconv_open(0x239dcd0, ISO-8859-1)
09:03:25.327102 25546 (iconv.c:187):local name for ISO-8859-1 is ISO-8859-1
09:03:25.327110 25546 (iconv.c:187):local name for UTF-8 is UTF-8
09:03:25.327113 25546 (iconv.c:187):local name for UCS-2LE is UCS-2LE
09:03:25.327115 25546 (iconv.c:187):local name for UCS-2BE is UCS-2BE
09:03:25.327117 25546 (iconv.c:349):setting up conversions for client charset "ISO-8859-1"
09:03:25.327120 25546 (iconv.c:351):preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
09:03:25.327128 25546 (iconv.c:391):preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
09:03:25.327136 25546 (iconv.c:394):tds_iconv_open: done
09:03:25.327146 25546 (net.c:207):Connecting to {ip} port 1433 (TDS version 7.1)
09:03:25.327344 25546 (net.c:272):tds_open_socket: connect(2) returned "Operation now in progress"
09:03:25.329401 25546 (net.c:312):tds_open_socket() succeeded
09:03:25.329418 25546 (util.c:156):Changed query state from DEAD to IDLE
09:03:25.329427 25546 (net.c:743):Sending packet
.
.
.
.
09:03:25.345470 25546 (token.c:337):looking for login token, got  aa(ERROR)
09:03:25.345473 25546 (token.c:122):tds_process_default_tokens() marker is aa(ERROR)
09:03:25.345478 25546 (token.c:2588):tds_process_msg() reading message 18452 from server
09:03:25.345487 25546 (token.c:2661):tds_process_msg() calling client msg handler
09:03:25.345501 25546 (token.c:2674):tds_process_msg() returning TDS_SUCCEED
09:03:25.345504 25546 (token.c:337):looking for login token, got  fd(DONE)
09:03:25.345506 25546 (token.c:122):tds_process_default_tokens() marker is fd(DONE)
09:03:25.345509 25546 (token.c:2339):tds_process_end: more_results = 0
                was_cancelled = 0
                error = 1
                done_count_valid = 0
09:03:25.345513 25546 (token.c:2355):tds_process_end() state set to TDS_IDLE
09:03:25.345515 25546 (token.c:2370):                rows_affected = 0
09:03:25.345518 25546 (token.c:438):tds_process_login_tokens() returning TDS_FAIL
09:03:25.345520 25546 (login.c:466):login packet accepted
09:03:25.32672925546(log.c:196):启动FreeTDS 0.91的日志文件
2019-08-26 09:03:25,带有调试标志0xffff。
09:03:25.32692525546(util.c:331):tdserror(0x239dbb0,0x239dcd0,100,0)
09:03:25.326961 25546(util.c:361):tdserror:客户端库返回TDS_INT_CANCEL(2)
09:03:25.32696625546(util.c:384):tdserror:返回TDS\u INT\u CANCEL(2)
09:03:25.3269722546(iconv.c:330):tds_iconv_打开(0x239dcd0,ISO-8859-1)
09:03:25.3271022546(iconv.c:187):ISO-8859-1的本地名称为ISO-8859-1
09:03:25.32711025546(iconv.c:187):UTF-8的本地名称是UTF-8
09:03:25.32711325546(iconv.c:187):UCS-2LE的本地名称为UCS-2LE
09:03:25.327115 25546(iconv.c:187):UCS-2BE的本地名称为UCS-2BE
09:03:25.32711725546(iconv.c:349):为客户端字符集“ISO-8859-1”设置转换
09:03:25.327120 25546(iconv.c:351):为“ISO-8859-1”“UCS-2LE”转换准备iconv
09:03:25.327128 25546(iconv.c:391):为“ISO-8859-1”“UCS-2LE”转换准备iconv
09:03:25.32713625546(iconv.c:394):tds_iconv_打开:完成
09:03:25.327146 25546(net.c:207):连接到{ip}端口1433(TDS版本7.1)
09:03:25.327344 25546(net.c:272):tds_open_套接字:connect(2)返回“操作正在进行”
09:03:25.329401 25546(net.c:312):tds_open_socket()成功
09:03:25.329418 25546(util.c:156):将查询状态从死状态更改为空闲状态
09:03:25.329427 25546(net.c:743):发送数据包
.
.
.
.
09:03:25.345470 25546(令牌。c:337):查找登录令牌,获得aa(错误)
09:03:25.345473 25546(token.c:122):tds_process_default_tokens()标记为aa(错误)
09:03:25.34547825546(token.c:2588):tds_process_msg()正在从服务器读取消息18452
09:03:25.34548725546(token.c:2661):tds_process_msg()调用客户端消息处理程序
09:03:25.345501 25546(token.c:2674):返回tds\u成功的tds\u进程\u msg()
09:03:25.3455042546(token.c:337):查找登录令牌,获得fd(完成)
09:03:25.34550625546(token.c:122):tds_process_default_tokens()标记为fd(完成)
09:03:25.345509 25546(token.c:2339):tds\u进程\u结束:更多\u结果=0
取消了吗=0
错误=1
已完成\u计数\u有效=0
09:03:25.3455132546(token.c:2355):tds_进程结束()状态设置为tds_空闲
09:03:25.345515 25546(令牌c:2370):受影响的行=0
09:03:25.34551825546(token.c:438):tds\u进程\u登录\u令牌()返回tds\u失败
09:03:25.345520 25546(login.c:466):接受登录数据包
谁能告诉我我在配置或其他方面做错了什么。 FreeTds在运行“-C”命令时返回版本为4.2。不确定这是否是问题所在,因为我正在传递配置文件的“-I”参数

/usr/bin/tsql-S{ip}-U“{domain}\{username}”-I/etc/freetds/freetds.conf

我相信,当您使用它时,它会识别为SQL身份验证。通常,
Windows身份验证
被识别为当前登录的用户,这要求服务器加入域控制器管理的域kerberos身份验证。否则,它需要来自unix/linux的全套配置kerberos身份验证

如果您没有任何安全问题,我建议您使用
SQL身份验证
,您可以通过SSMS->Server Properties->security(选项卡)->SQL Server和Windows身份验证(需要重新启动服务)来更改它

/usr/bin/tsql-S{ip}-U“{domain}\{username}”-I/etc/freetds/freetds.conf

我相信,当您使用它时,它会识别为SQL身份验证。通常,
Windows身份验证
被识别为当前登录的用户,这要求服务器加入域控制器管理的域kerberos身份验证。否则,它需要来自unix/linux的全套配置kerberos身份验证


如果您没有任何安全问题,我建议您使用
SQL身份验证
,您可以通过SSMS->Server Properties->security(选项卡)->SQL Server和Windows身份验证-(必需的服务重新启动)对其进行更改。

这真的很烦人,我以前也为此踢过自己,但您需要使用单引号:

/usr/bin/tsql -S {ip} -U '{domain}\{username}' -I /etc/freetds/freetds.conf
例如,我刚刚测试了:

$tsql-S myserver.example.com-p 1433-U“MYDOMAIN\myuser”
密码:
区域设置为“en_US.UTF-8”
区域设置字符集为“UTF-8”
使用默认字符集“UTF-8”
来自CDW-SQL0101第1行的Msg 18452(严重程度14,状态1):
“登录失败。该登录来自不受信任的域,不能与Windows身份验证一起使用。”
错误20002(严重性9):
自适应服务器连接失败
错误20002(严重性9):
自适应服务器连接失败
连接到服务器时出现问题
$tsql-S myserver.example.com-p 1433-U'MYDOMAIN\myuser'
密码:
区域设置为“en_US.UTF-8”
区域设置字符集为“UTF-8”
使用默认字符集“UTF-8”
1> 从sys.tables中选择TOP 1 name、object_id;
2> 去
名称对象\u id
spt_备用数据库117575457
(1行受影响)
1>

这是在CentOS 7.6和FreeTDS 0.95上实现的,但也可以在您的设置中使用。祝你好运

这真的很烦人,我以前也为此自责过,但你需要使用单引号:

/usr/bin/tsql -S {ip} -U '{domain}\{username}' -I /etc/freetds/freetds.conf
例如,我刚刚测试了:

$tsql-S myserver.example.com-p 1433-U“MYDOMAIN\myuser”
密码:
区域设置为“en_US.UTF-8”
区域设置字符集为“UTF-8”
使用默认字符集“UTF”