"Unknown host machine name." 在 FreeBSD + unixODBC + FreeTDS 上

"Unknown host machine name." on FreeBSD + unixODBC + FreeTDS

我在从我的 FreeBSD 10.1 服务器连接到 Microsoft SQL Server 2012 时遇到一些问题。

我通过端口安装了 FreeTDS 和 unixODBC。我编译了带有 unixODBC 支持的 FreeTDS。这是我的 freetds.conf:

    [server1]
      host = 192.168.100.147
      port = 1433
      tds version = 7.2

调用 tsql 工作正常。

但是当我尝试通过 odbc 与 "osql" 或 "isql" 连接时,连接失败并出现以下错误:

checking shared odbc libraries linked to isql for default directories...
    trying /tOH ... no
    trying /tOH ... no
    trying /tmp/sqlH ... no
    trying /tmp/sqlH ... no
    trying /usr/locH ... no
    trying /usr/locH ... no
    trying /tmp/sql.log ... no
    trying /home ... no
    trying /.odbc.ini ... no
    trying /usr/local/etc ... OK
checking odbc.ini files
    reading /root/.odbc.ini
[server1] not found in /root/.odbc.ini
    reading /usr/local/etc/odbc.ini
[server1] found in /usr/local/etc/odbc.ini
found this section:
    [server1]
      Driver = FreeTDS
      Servername = server1
looking for driver for DSN [server1] in /usr/local/etc/odbc.ini
  found driver line: "      Driver = FreeTDS"
  driver "FreeTDS" found for [server1] in odbc.ini
found driver named "FreeTDS"
"FreeTDS" is not an executable file
looking for entry named [FreeTDS] in /usr/local/etc/odbcinst.ini
  found driver line: "      Driver = /usr/local/lib/libtdsodbc.so"
  found driver /usr/local/lib/libtdsodbc.so for [FreeTDS] in odbcinst.ini
/usr/local/lib/libtdsodbc.so is an executable file
Using ODBC-Combined strategy
DSN [server1] has servername "server1" (from /usr/local/etc/odbc.ini)
cannot read "/root/.freetds.conf"
/usr/local/etc/freetds/freetds.conf is a readable file
looking for [server1] in /usr/local/etc/freetds/freetds.conf
found this section:
    [server1]
        host = 192.168.100.147
        port = 1433
        tds version = 7.2
looking up hostname for ip address 192.168.100.147

Configuration looks OK.  Connection details:

                   DSN:    server1
              odbc.ini:    /usr/local/etc/odbc.ini
                Driver:    /usr/local/lib/libtdsodbc.so
       Server hostname:    sqlsrv01
               Address:    192.168.100.147

Attempting connection as sa ...
+ isql server1 sa foobar -v
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
[ISQL]ERROR: Could not SQLConnect

这是我odbc.ini的内容:

[server1]
  Driver = FreeTDS
  Servername = server1

这是我的 odbcinst.ini:

[FreeTDS]
  Driver = /usr/local/lib/libtdsodbc.so
  Client Charset = UTF-8
  UsageCount = 1

我阅读了很多关于使用精确命名 inf odbc.ini 和 freetds.conf 的帖子,但连接一直失败。

有人可以帮忙吗?

我现在可以回答我自己的问题了。

根据 unixODBC 邮件列表的提示 Link 我调用了

odbcinst -i -s -f /usr/local/etc/odbc.ini

现在我可以通过 osql 连接到服务器了。