在FreeBSD + unixODBC + FreeTDS中出现“未知的主机名称。”

3

我在我的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正常运行。

但是当我尝试通过"osql"或"isql"进行ODBC连接时,连接失败并显示以下错误:

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

我读了几篇关于使用确切命名的 odbc.ini 和 freetds.conf 的帖子,但连接仍然失败。
有人能帮忙吗?

1
尝试在 ServerFault 上提出这个问题,因为这与服务器管理有关,与编程无关。 - Antxon
1
我会做的。谢谢 :) - user1056212
我投票关闭此问题,因为它应该迁移到 ServerFault。 - Roland Smith
1个回答

4

我现在能够回答自己的问题了。

在 unixODBC 邮件列表 链接 中得到提示后,我执行了以下步骤:

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

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

@Ryosaku,你能否开一个新的问题,并粘贴你odbc.ini的内容? - user1056212

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接