sql-server - FreeTDS 可以工作,但 ODBC 无法连接

标签 sql-server odbc ubuntu-12.04 freetds isql

我正在尝试使用 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进行操作。here和 2.here

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

最佳答案

问题出在 odbc.ini 中的这一行

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

对于那些也遇到此问题的人,还请检查

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

关于sql-server - FreeTDS 可以工作,但 ODBC 无法连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18232386/

相关文章:

sql-server - 如何将大于 24 小时的 TimeSpan 映射到 SQL Server Code First?

php - 无法使用 PHP 和 Codeigniter 从 PHP Azure 连接到 SQL Server Azure

ruby-on-rails - Rails 连接 oracle 引发错误

ubuntu-12.04 - 为 mysqldump 输出设置文件权限

sql - 检索这些记录的查询是什么?

mysql - 在 SSIS 包中使用临时表

sql-server - 尝试 SQL 注入(inject)攻击 - 他们想做什么?

odbc - (可能)ODBC SQL Server 连接字符串中的非法字符 PWD=

c# - 在 SQL Server 表中序列化 DataSet 的最快方法

linux - 如何在脚本中使用 sudo 执行多个命令