FreeTDS正常工作,但ODBC无法连接。

22

我正尝试使用FreeTDS和unixODBC从Ubuntu 12.04 Web服务器连接到MSSQL服务器。

使用tsql,我可以连接到该服务器:

~$ tsql -S dbs3 -U <username> -P <password>

没问题。

然而,当我尝试使用isql连接时,我会收到以下错误消息:

~$ isql -v database3 <username> <password>
[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

[database3]
Driver=FreeTDS
TDS_Version=8.0
Servername=dbs3
Port=1433
Database=benchmark_res

odbcinst.ini

[FreeTDS]
Description=FreeTDS v0.91
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsS.so
Trace=Yes
TraceFile=/tmp/freetds.log
ForceTrave=Yes
UsageCount=1

freetds.conf

# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database
# server specific section
[global]
    # TDS protocol version
;   tds version = 4.2

    # Whether to write a TDSDUMP file for diagnostic purposes
    # (setting this to /tmp is insecure on a multi-user system)
;   dump file = /tmp/freetds.log
;   debug flags = 0xffff

    # Command and connection timeouts
;   timeout = 10
;   connect timeout = 10

    # If you get out-of-memory errors, it may mean that your client
    # is trying to allocate a huge buffer for a TEXT field.
    # Try setting 'text size' to a more reasonable limit
    text size = 64512

# A typical Sybase server
[egServer50]
    host = symachine.domain.com
    port = 5000
    tds version = 5.0

# A typical Microsoft server
[egServer70]
    host = ntmachine.domain.com
    port = 1433
    tds version = 7.0

[dbs3]
    host = <server-ip>
    port = 1433
    tds version = 8.0

我按照这里的安装指南 1. 这里 和 2. 这里

为什么isql无法正确连接?
我的猜测是错误非常明显,但我只是太蠢了看不到 :D

3个回答

13

问题出在 odbc.ini 文件的这一行。

[database3] must be [dbs3] in your case.

对于那些也遇到这个问题的人,请检查

ServerName  = *Points to the name of the server configured in freetds.conf*

如果修复这个问题没有解决,你接下来会考虑做什么? - Adrian Keister

1

我曾经遇到同样的问题,后来发现每次修改 odbc.ini 后都需要执行以下操作:

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

之后,测试了这个:


isql -v SERVER USER PWD 

并且我得到了这个输出:

+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>

1
如果odbc找不到数据源,那么就意味着你提供的是错误的。你可能正在尝试连接到dbs3,如果在odbc.ini中没有它,则会失败。你应该连接到[database3]以进行ODBC连接。
isql -v database3 <username> <password>

这就是我正在做的事情。我使用带有tsql的dbs3: tsql -S dbs3 -U <username> -P <username>。按照您提到的方式使用isql会返回这些错误。 - AndMim
你已经将 database3 添加到你的主机文件中了吗? - meda
不,根据我的理解,这应该通过我在freetds.conf中输入的IP来解决。 - AndMim
freetds和odbc - meda
ODBC:sudo apt-get install unixodbc-dev unixodbc-bin unixodbcfreeTDS:我从源代码构建了它。我在原问题中提供了我遵循的说明链接。 - AndMim

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