FreeTDS连接问题

时间:2011-09-28 23:45:14

标签: sql-server linux windows freetds

我正在使用FreeTDS 0.91连接到远程MSSQL服务器,但到目前为止所有尝试都没有结果。

在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

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()

看起来这可能是SQL服务器的问题,还是我安装或配置了FreeTDS错误?

太丢了。请帮忙。


当我通过telnet连接到服务器时,这是我回复的响应:

尝试70.70.218.13 ...
  连接到70.70.218.13。
  逃脱角色是'^]'   ^^
  连接由外国主机关闭。

这是否意味着与主机的telnet连接成功了?

SQL数据库在Windows服务器上运行。连接到Windows服务器(就像通过远程桌面一样)是否是用于主机名和端口的正确值?或者我是否必须在Windows服务器上找到SQL服务器的直接主机名?

3 个答案:

答案 0 :(得分:24)

汗。

我刚遇到同样的情况。我通过在家中添加.freetds.conf解决了这个问题,

[global]
    # TDS protocol version
    tds version = 7.0 

我知道这正是大多数FreeTDS连接问题的答案。

这种方法也由@Michael Berkowski提供。

答案 1 :(得分:0)

对于五年的死灵事件道歉,似乎当tsql成功连接到开放端口时也会发生此错误,但是侦听器是除SQL Server之外的某些服务。似乎FreeTDS没有尝试检查它是否在登录时与SQL Server以外的服务进行通信,因此错误消息是神秘的。 (就我而言,我使用的是远程桌面的端口号。)

答案 2 :(得分:0)

如果您不想创建.freetds.conf,只需设置TDSVER环境变量(例如,在Windows上连接到SQL Server 2008使用TDS版本7.3):

set TDSVER=7.3

(* nix使用export)。

有关更多环境变量,请参阅http://www.freetds.org/userguide/envvar.htm

有关不同RDBMS的TDS版本,请参阅http://www.freetds.org/userguide/choosingtdsprotocol.htm

您还可以指定日志文件的路径,该路径可以通过设置环境变量TDSDUMP来提供更多信息,这将有助于解决问题并显示查找配置文件的位置。 e.g。

set TDSDUMP=C:\temp\freetds.log

在我的情况下,设置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

显然FreeTDS没有解析字符串“CP1252; LC_CTYPE = English_United States.1252; LC_MONETARY = C; LC_NUMERIC = C; LC_TIME = C”

中的字符集名称

我创建了一个.freetds.conf文件,其中包含以下内容:

[global]
    tds version = 7.3           # version 7.3 for MSSQL 2008
    client charset = UTF-8      # so that we can get unicode characters

并按照日志文件的建议将其保存到C:\Windows\System32\config\systemprofile\AppData\Roaming\,这为我解决了问题。