sql-server - FreeTDS 无法从 odbc.ini 读取服务器名称

标签 sql-server ubuntu odbc freetds

我正在尝试设置 FreeTDS 以连接到 Ubuntu 14.04 和 FreeTDS 4.2 中的 mssql 服务器

但是,由于未知原因,osql 无法读取服务器名称 设置。 如果我使用 isql,它就可以工作。但是我的程序使用 odbc.ini 设置。

我做错了什么?

我的odbc.ini;

[ODBC Data Sources]
Test = My Test Server

[mssql]
Description = My Test Server
Driver      = FreeTDS
Trace       = No
TDS_Version = 4.2
Servername  = mssql

命令

~$ osql -S mssql -U user -P password 
checking shared odbc libraries linked to isql for default directories...
strings: '': No hay tal fichero
    trying /tmp/sql ... no
    trying /tmp/sql ... no
    trying /etc ... OK
checking odbc.ini files
    reading /home/business/.odbc.ini
[mssql] not found in /home/business/.odbc.ini
    reading /etc/odbc.ini
[mssql] found in /etc/odbc.ini
found this section:
    [mssql]
    Description = My Test Server
    Driver      = FreeTDS
    Trace       = No
    TDS_Version = 4.2
    Servername  = mssql

looking for driver for DSN [mssql] in /etc/odbc.ini
  found driver line: "  Driver      = FreeTDS"
  driver "FreeTDS" found for [mssql] in odbc.ini
found driver named "FreeTDS"
"FreeTDS" is not an executable file
looking for entry named [FreeTDS] in /etc/odbcinst.ini
  found driver line: "  Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so"
  found driver /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so for [FreeTDS] in odbcinst.ini
/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so is an executable file
Using ODBC-Combined strategy
DSN [mssql] has servername "" (from /etc/odbc.ini)

最佳答案

您需要在此处修复一些问题。首先,在 odbc.ini 中,它是“Server”而不是“Servername”。这是一个例子。

odbc.ini:

[myserver]
Driver = FreeTDS
Server = myserver.mydomain.com
Port = 1433
TDS_Version = 7.2

freetds.conf:

[myserver]
host = myserver.mydomain.com
port = 1433
tds version = 7.2

此外,您还需要使用更高的 TDS 版本。 TDS 4.2 适用于 Microsoft SQL Server 6.0!尽管有文档,我发现它并不适用于所有产品。要选择合适的 TDS 版本,请参阅此处:

http://www.freetds.org/userguide/choosingtdsprotocol.htm

您很可能需要版本 7.2 或 7.3。祝你好运!

关于sql-server - FreeTDS 无法从 odbc.ini 读取服务器名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34107983/

相关文章:

SQL Server 更改表查询(语法不正确)

sql-server - 全文未索引 varbinary 列(使用 html)

mysql - ADODB.Command 错误 odbc mysql ASP(Classic not .net)

linux - 从另一个基于 Linux 的系统到 Informix 数据库的 ODBC 连接

java - 从 lotus notes 数据库中获取表名

sql - 同一列 SQL 中 2 个日期的 DateDiff

MySQL/SQL Server...作为一个完整的解决方案协同工作

linux - shell 脚本中的 for x in {1..10} 仅运行一次

linux - 安装驱动程序会增加 linux 内核内存占用吗?

python - 无法插入 Postgresql