【问题标题】:freeTDS not using its configfreeTDS 不使用其配置
【发布时间】:2012-10-15 12:37:39
【问题描述】:

我决定使用 FreeTDS 驱动程序和 unixODBC 来管理基于 LAMP 的应用程序与远程 MsSQL 数据库之间的 PDO 连接。 不幸的是,驱动程序似乎没有读取 freetds.conf 文件,也没有直接通过服务器的 CLI 设置环境变量,也没有通过 putenv() 函数在 php 文件中指定环境变量。

现在一些数据:

  1. 当我 ping 服务器时 - 没有数据包丢失。
  2. 当我在 1433 端口上远程登录服务器时 - 连接已建立
  3. 当我使用命令时

    TDSVER=7.0 tsql -H >IP< -p 1433 -U username
    

    系统提示我输入密码并建立连接。

  4. 在命令前没有 TDSVER - 连接失败并显示以下消息:

    Error 20017 (severity 9):
        Unexpected EOF from the server
        OS error 115, "Operation now in progress"
    Error 20002 (severity 9):
        Adaptive Server connection failed
    There was a problem connecting to the server
    
  5. tsql -C 命令会回显这样的输出:

    Compile-time settings (established with the "configure" script)
                           Version: freetds v0.91
            freetds.conf directory: /usr/local/etc
    MS db-lib source compatibility: yes
       Sybase binary compatibility: no
                     Thread safety: yes
                     iconv library: yes
                       TDS version: 5.0
                             iODBC: no
                          unixodbc: yes
             SSPI "trusted" logins: no
                          Kerberos: no
    
  6. freetds.conf 在上面给出的位置有这个条目:

    [MSSQL]
    host = >IP<
    port = 1433
    tds version = 7.0
    
  7. ISQL 也失败了:

    isql -v MSSQL
    [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
    [01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed
    [ISQL]ERROR: Could not SQLConnect
    
  8. 我的 odbc.ini :

    [MSSQL]
    Description = MS SQL Server
    Driver = FreeTDS
    TDS_Version = 7.0
    Server = >IP<
    UID = username
    PWD = password
    ReadOnly = No
    Port = 1433
    

我想解决方案真的很简单,但我太笨了,找不到它......

【问题讨论】:

  • 我通过 ddg 发现了这个问题:“freetds linux not working”,我的问题是我没有专门定义端口。

标签: sql-server linux ubuntu-10.04 freetds


【解决方案1】:

不是连接到IP,而是尝试连接到配置部分的名称?例如:

isql -v MSSQL

【讨论】:

  • 你也有odbc.ini 吗?见stackoverflow.com/questions/8010361/…
  • 尝试将Server = 10.2.201.2中的odbc.ini改成Server = MSSQL
  • 我很确定这种行为的原因在于 FreeTDS 不使用 Microsoft SQL Server 所需的 TDSVER=7.0
  • 尝试将TDS_Version 更改为TDS Version?虽然它应该从 tds 配置文件中获取它
  • 是的,我改了,结果还是和以前一样。
【解决方案2】:

我的直觉是,您需要将 freetds.conf 和 odbc.ini 文件中的 tds version = 7.0 更改为 tds version = 8.0 并且您需要一些东西您的 odbcinst.ini 文件。这是我在 Ubuntu 12.04 服务器上与远程 MSSQL 服务器通信的工作:

freetds.conf

# Define a connection to the MSSQL server.
[mssql]
    host = myserver
    port = 1433
    tds version = 8.0

odbc.ini

# Define a connection to the MSSQL server.
# The Description can be whatever we want it to be.
# The Driver value must match what we have defined in /etc/odbcinst.ini
# The Database name must be the name of the database this connection will connect to.
# The ServerName is the name we defined in /etc/freetds/freetds.conf
# The TDS_Version should match what we defined in /etc/freetds/freetds.conf
[mssql]
Description             = MSSQL Server
Driver                  = freetds
Database                = MyDB
ServerName              = myserver
TDS_Version             = 8.0

odbcinst.ini

# Define where to find the driver for the Free TDS connections.
[freetds]
Description     = MS SQL database access with Free TDS
Driver          = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup           = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount      = 1

【讨论】:

  • 非常感谢,我会尽量采纳你的建议,因为我明天要上班
  • 我刚刚在 centos 6 64bit 上复制了这个。它不起作用
  • 任何人有任何想法在哪里获得适用于 FreeTDS 的 Mac OS X 的 MSSQL 驱动程序?
【解决方案3】:

我遇到了同样的问题,但我的配置已经正确设置。问题是 freetds.conf 识别的 TDS 版本在新版本中发生了变化,但显然旧版本仍然在 TDSVER 环境变量中工作。一旦我将配置文件中的版本设置为 7.1 而不是 8.0,一切都开始工作了。

【讨论】:

  • 为我工作!谢谢。经过数小时的测试和谷歌搜索,我无法相信这就是让系统启动和运行所需的全部内容。
  • 我通过export TDSDUMP=/temp/freetds.log~/.bashrc 中调试了我的设置,这清楚地表明配置文件没有设置tds 版本。一旦我设置了环境变量export TDSVER=8.0,一切正常。
【解决方案4】:

我今天花了很长时间调试一个类似的问题。我在 freetds.conf 中设置了“TDS 版本”,但它没有在我的 ODBC 连接中使用。在阅读了freetds源代码(connectparams.c:odbc_parse_connect_string)后,我发现:

  • 如果您的连接字符串使用“SERVER=”,则 freetds.conf 和 odbc.ini 都会被忽略
  • 如果您的连接字符串使用“SERVERNAME=”,则使用相应 freetds.conf 服务器中的设置
  • 如果您的连接字符串使用“DSN=”,则使用相应 odbc.ini DSN 中的设置

odbcinst.ini 是一个红鲱鱼。 FreeTDS 从不检查设置。

您在连接字符串中指定的设置 始终受到尊重。它还始终尊重 TDSVER 等环境变量。

【讨论】:

  • 感谢您的研究:它证实了我刚才在抨击的内容:DBI:ODBC not reading /etc/freetds/freetds.conf when I using the Server= parameter in my DSN-less connection string (并且strings /usr/lib/odbc/libtdsodbc.so|grep conf 显示库知道在哪里找到配置文件。运行strace ... -e open ... 也确认没有尝试读取freetds.conf
  • 示例 4.3 here 证实了您的研究。再次感谢。
  • 如果我尝试使用 SERVERNAME=... 通过 PHP 连接,则会收到错误消息:“SQLSTATE[08001] SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]无法连接到数据source" 它只适用于 SERVER=... 知道为什么吗?
  • @kinske 我遇到了与SERVERNAME 相同的错误,而SERVER 有效。
  • 我正在使用HOST=xx.xx.xx.xx 连接,并且在连接之前需要在我的PHP 代码中添加putenv("TDSVER=8.0");
【解决方案5】:

最初的TDSVER=7.0 问题已通过在我的odbc.ini 文件末尾添加以下内容得到解决:

[Default]
Driver=/usr/local/lib/libtdsodbc.so

【讨论】:

    猜你喜欢
    • 2016-11-16
    • 2012-09-09
    • 2019-12-20
    • 2018-02-03
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2017-05-19
    • 2019-04-04
    相关资源
    最近更新 更多