Linux FreeTDS 连接问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7590944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FreeTDS connection problems
提问by Kamran Khan
I'm using FreeTDS 0.91 to connect to a remote MSSQL server but all attempts have borne no fruit thus far.
我正在使用 FreeTDS 0.91 连接到远程 MSSQL 服务器,但到目前为止所有尝试都没有结果。
Upon doing a tsql command on my Unix, I get the following error:
在我的 Unix 上执行 tsql 命令时,我收到以下错误:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20004 (severity 9)
Read from the server failed
OS error 104, "Connection reset by peer"
Error 20002 (severity 9)
Adaptive Server connection failed
There was a problem connecting to the server
The freetds.log has the following in it:
freetds.log 中包含以下内容:
16:05:49.144905 20207 (log.c:196):Starting log file for FreeTDS 0.91
on 2011-09-28 16:05:49 with debug flags 0xffff.
16:05:49.145281 20207 (iconv.c:330):tds_iconv_open(0x3d29320, UTF-8)
16:05:49.145426 20207 (iconv.c:187):local name for ISO-8859-1 is ISO-8859-1
16:05:49.145448 20207 (iconv.c:187):local name for UTF-8 is UTF-8
16:05:49.145459 20207 (iconv.c:187):local name for UCS-2LE is UCS-2LE
16:05:49.145469 20207 (iconv.c:187):local name for UCS-2BE is UCS-2BE
16:05:49.145479 20207 (iconv.c:349):setting up conversions for client charset "UTF-8"
16:05:49.145489 20207 (iconv.c:351):preparing iconv for "UTF-8" "UCS-2LE" conversion
16:05:49.145508 20207 (iconv.c:391):preparing iconv for "ISO-8859-1" "UCS-2LE" conversion
16:05:49.145533 20207 (iconv.c:394):tds_iconv_open: done
16:05:49.145550 20207 (net.c:205):Connecting to 70.70.218.13 port 2600 (TDS version 7.0)
16:05:49.145686 20207 (net.c:270):tds_open_socket: connect(2) returned "Operation now in progress"
16:05:49.236008 20207 (net.c:310):tds_open_socket() succeeded
16:05:49.236061 20207 (util.c:156):Changed query state from DEAD to IDLE
16:05:49.236083 20207 (login.c:782):quietly sending TDS 7+ login packet
16:05:49.236173 20207 (token.c:328):tds_process_login_tokens()
16:05:49.857930 20207 (util.c:331):tdserror(0x3d29080, 0x3d29320, 20004, 104)
16:05:49.858072 20207 (util.c:361):tdserror: client library returned TDS_INT_CANCEL(2)
16:05:49.858090 20207 (util.c:384):tdserror: returning TDS_INT_CANCEL(2)
16:05:49.858114 20207 (util.c:156):Changed query state from IDLE to DEAD
16:05:49.858137 20207 (token.c:337):looking for login token, got 0()
16:05:49.858155 20207 (token.c:122):tds_process_default_tokens() marker is 0()
16:05:49.858168 20207 (token.c:125):leaving tds_process_default_tokens() connection dead
16:05:49.858179 20207 (login.c:466):login packet accepted
16:05:49.858189 20207 (util.c:331):tdserror(0x3d29080, 0x3d29320, 20002, 0)
16:05:49.858209 20207 (util.c:361):tdserror: client library returned TDS_INT_CANCEL(2)
16:05:49.858220 20207 (util.c:384):tdserror: returning TDS_INT_CANCEL(2)
16:05:49.858232 20207 (mem.c:615):tds_free_all_results()
Does this at all seem like it could be an issue with the SQL server, or am I installing or have configured FreeTDS wrong?
这似乎是 SQL 服务器的问题,还是我安装或配置了错误的 FreeTDS?
So lost. Please help.
所以输了。请帮忙。
When I connect to the server via telnet, this is the response I get back:
当我通过 telnet 连接到服务器时,这是我得到的响应:
Trying 70.70.218.13...
Connected to 70.70.218.13.
Escape character is '^]'.
^^
Connection closed by foreign host.
正在尝试 70.70.218.13...
连接到 70.70.218.13。
转义字符是“^]”。
^^
连接被外部主机关闭。
Would this mean that the telnet connection to the host was successful?
这是否意味着与主机的 telnet 连接成功?
The SQL database is run on a windows server. Would connecting to the Windows server (just like you would through remote desktop) be the right sort of values to use for the hostname and port? Or would I have to find a direct hostname to the SQL server on the windows server?
SQL 数据库在 Windows 服务器上运行。连接到 Windows 服务器(就像通过远程桌面一样)是否适合用于主机名和端口?或者我是否必须在 Windows 服务器上找到 SQL 服务器的直接主机名?
回答by fangzhzh
Khan.
汗。
I just encountered this same situation. And I resolved this problem by adding a .freetds.conf to my home,
我刚刚遇到了同样的情况。我通过在我的家中添加一个 .freetds.conf 解决了这个问题,
[global]
# TDS protocol version
tds version = 7.0
And I know this is exactly the answer to most FreeTDS connect problems.
我知道这正是大多数 FreeTDS 连接问题的答案。
And this method is also provided by @Michael Berkowski.
这个方法也是由@Michael Berkowski 提供的。
回答by jbarlow
With apologies for the five year necromancy, it appears that this error will also occur when tsql successfully connects to an open port, but the listener is some service other than SQL Server. It seems FreeTDS does not try to check if it's talking to a service other than SQL Server on login, so the error messages are cryptic. (In my case, I was using the port number for Remote Desktop.)
为五年的死灵道歉,看来tsql成功连接到一个开放端口时也会出现这个错误,但侦听器是SQL Server以外的一些服务。似乎 FreeTDS 在登录时不会尝试检查它是否正在与 SQL Server 以外的服务通信,因此错误消息很神秘。(就我而言,我使用的是远程桌面的端口号。)
回答by isapir
If you don't want to create .freetds.conf
you can simply set the TDSVER
Environment variable instead (e.g. on Windows to connect to SQL Server 2008 use TDS version 7.3):
如果你不想创建,.freetds.conf
你可以简单地设置TDSVER
环境变量(例如在 Windows 上连接到 SQL Server 2008 使用 TDS 7.3 版):
set TDSVER=7.3
(for *nix use export
).
(用于 *nix 使用export
)。
See http://www.freetds.org/userguide/envvar.htmfor more environment variables.
有关更多环境变量,请参阅http://www.freetds.org/userguide/envvar.htm。
See http://www.freetds.org/userguide/choosingtdsprotocol.htmfor TDS versions of different RDBMSs
有关不同 RDBMS 的 TDS 版本,请参阅http://www.freetds.org/userguide/choosingtdsprotocol.htm
You can also specify a path for a log file which can provide more information by setting the environment variable TDSDUMP
, which will help troubleshoot problems and show you where config files are looked for. e.g.
您还可以指定日志文件的路径,该路径可以通过设置环境变量来提供更多信息TDSDUMP
,这将有助于解决问题并显示查找配置文件的位置。例如
set TDSDUMP=C:\temp\freetds.log
In my case setting the TDSDUMP variable revealed an error in the logs:
在我的情况下,设置 TDSDUMP 变量显示日志中出现错误:
iconv.c:346:setting up conversions for client charset "CP1252;LC_CTYPE=English_United States.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C"
iconv.c:348:preparing iconv for "CP1252;LC_CTYPE=English_United States.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C" <-> "UCS-2LE" conversion
iconv.c:423:tds_iconv_info_init: client charset name "-1" invalid
Apparently FreeTDS didn't parse the charset name from the string "CP1252;LC_CTYPE=English_United States.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C"
显然 FreeTDS 没有从字符串“CP1252;LC_CTYPE=English_United States.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C”中解析字符集名称
I created a .freetds.conf
file with the following contents:
我创建了一个.freetds.conf
包含以下内容的文件:
[global]
tds version = 7.3 # version 7.3 for MSSQL 2008
client charset = UTF-8 # so that we can get unicode characters
And saved it to C:\Windows\System32\config\systemprofile\AppData\Roaming\
as suggested by the log file, which fixed the problem for me.
并C:\Windows\System32\config\systemprofile\AppData\Roaming\
按照日志文件的建议将其保存,这为我解决了问题。