在FreeBSD上通过FreeTDS连接到SQL Server 2005的问题

我尝试使用以下命令从FreeBSD服务器连接到SQL Server 2005:

tsql -H DEV -p 1433 -U **** 

这会导致以下错误消息:

 locale is "C" locale charset is "US-ASCII" Password: Msg 20004, Level 9, State 0, Server OpenClient, Line 0 Read from SQL server failed. Msg 20014, Level 9, State 0, Server OpenClient, Line 0 Login incorrect. There was a problem connecting to the server 

由于错误消息报告“login不正确”,我的第一步是validation我确实input了正确的用户名和密码。 这是一个SQL Serverlogin(即不是Windows身份validation),我已经确保它正确input区分大小写。 请注意,我可以使用来自Windows客户端的相同login名进行连接,而不会出现任何问题。

我的下一步是从FreeTDS转储日志:

 util.c:288:Starting log file for FreeTDS 0.64 on 2011-04-12 16:29:57 with debug flags 0x4fff. iconv.c:195:names for ISO-8859-1: ISO-8859-1 iconv.c:195:names for UTF-8: UTF-8 iconv.c:195:names for UCS-2LE: UCS-2LE iconv.c:195:names for UCS-2BE: UCS-2BE iconv.c:361:iconv to convert client-side data to the "US-ASCII" character set iconv.c:514:tds_iconv_info_init: converting "US-ASCII"->"UCS-2LE" net.c:168:Connecting to 10.5.5.226 port 1433. net.c:673:Sending packet ...snipped... net.c:673:Sending packet ...snipped... token.c:310:tds_process_login_tokens() util.c:119:Changing query state from IDLE to DEAD token.c:2252:tds_client_msg: #20004: "Read from SQL server failed.". Connection state is now 4. token.c:314:looking for login token, got 0() token.c:105:tds_process_default_tokens() marker is 0() token.c:108:leaving tds_process_default_tokens() connection dead util.c:119:Changing query state from DEAD to DEAD token.c:2252:tds_client_msg: #20014: "Login incorrect.". Connection state is now 4. mem.c:519:tds_free_all_results() 

我已经validation的另一件事是SQL Server实例接受通过TCP / IP的远程连接。 我也可以通过FreeBSD机器上的1433端口telnet到SQL Server,所以似乎没有一个普遍的连接问题。

所以,此刻,我死在水里了。 任何帮助诊断这些错误消息或build议其他事情尝试将非常感激。

出现“DB-Lib错误消息20004,严重性9:从SQL服务器读取失败”错误。

在Linux / * nix中,您可能会遇到以下行为:import _mssql c = _mssql.connect('hostname:portnumber','user','pass')Traceback(最近一次调用的最后一个):File“”,line 1,in _mssql.DatabaseException:DB-Lib错误消息20004,严重性9:从SQL Server读取失败。 DB-Lib错误消息20014,严重性9:login不正确。

当下列情况之一成立时,可能会发生这种情况:

  • freetds.conf文件找不到
  • freetds.conf文件中的tds版本不是7.0或4.2
  • 任何字符集都在freetds.conf中指定
  • 将无法识别的字符集传递给_mssql.connect()或pymssql.connect()方法。

出现此错误之后的“login不正确”是虚假的,真正的“login不正确”消息的代码为18456,严重性为14。

ref: http : //pymssql.sourceforge.net/faq.php

我结束了在这里的指示,现在一切正常完美:

http://kipb7.wordpress.com/2008/06/12/pyodbc-unixodbc-freetds-config/