首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >FreeTDS工作,但ODBC无法连接

FreeTDS工作,但ODBC无法连接
EN

Stack Overflow用户
提问于 2013-08-14 20:57:38
回答 3查看 32.4K关注 0票数 22

我正在尝试使用FreeTDS和unixODBC从Ubuntu12.04 and服务器上运行连接到MSSQL服务器。

使用tsql,我可以使用以下命令连接到服务器

代码语言:javascript
复制
~$ tsql -S dbs3 -U <username> -P <password>

这没问题。

然而,当我尝试连接isql时,我得到了以下错误信息:

代码语言:javascript
复制
~$ 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

代码语言:javascript
复制
[database3]
Driver=FreeTDS
TDS_Version=8.0
Servername=dbs3
Port=1433
Database=benchmark_res

odbcinst.ini

代码语言:javascript
复制
[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

代码语言:javascript
复制
# 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

EN

回答 3

Stack Overflow用户

发布于 2014-05-24 06:46:09

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

代码语言:javascript
复制
[database3] must be [dbs3] in your case.

对于那些也有这个问题的人,也可以查看

代码语言:javascript
复制
ServerName  = *Points to the name of the server configured in freetds.conf*
票数 13
EN

Stack Overflow用户

发布于 2013-08-14 23:52:40

如果odbc找不到数据源,这意味着您提供的数据源是错误的

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

您应该连接到[database3] for ODBC

代码语言:javascript
复制
isql -v database3 <username> <password>
票数 1
EN

Stack Overflow用户

发布于 2019-04-08 18:19:43

我也遇到了同样的问题,我发现每次修改odbc.ini后都必须执行以下命令:

代码语言:javascript
复制
odbcinst -i -s -f /etc/odbc.ini

在那之后,测试如下:

代码语言:javascript
复制
isql -v SERVER USER PWD 

我得到了下面的输出:

代码语言:javascript
复制
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18232386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档