gpt4 book ai didi

sql-server - freeTDS 不使用其配置

转载 作者:IT王子 更新时间:2023-10-29 00:21:18 29 4
gpt4 key购买 nike

我决定使用 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

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

最佳答案

我今天花了很长时间调试一个类似的问题。我在 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 等环境变量。

关于sql-server - freeTDS 不使用其配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13066716/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com