22

我正在尝试从带有 FreeTDS 和 unixODBC 的 Ubuntu 12.04 网络服务器运行连接到 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

4

3 回答 3

13

问题是 odbc.ini 中的这一行

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

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

ServerName  = *Points to the name of the server configured in freetds.conf*
于 2014-05-23T22:46:08.657 回答
1

如果 odbc 没有找到数据源,则意味着您提供了错误的数据源

dbs3如果您在 odbc.ini 中没有它,您可能正在尝试连接到哪个将失败

您应该连接到[database3]ODBC

isql -v database3 <username> <password>
于 2013-08-14T15:52:40.167 回答
1

我有同样的问题,我发现你必须在每次修改后执行以下操作odbc.ini

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

之后,对此进行了测试:

isql -v SERVER USER PWD 

我得到了这个输出:

+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>
于 2019-04-08T10:19:42.597 回答