本文介绍了odbc无法连接到OS X Lion上的MSSQL数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

odbc isql无法连接到数据源:

odbc isql was unable to connect to data source:

 $ isql SMS_GTWY username password -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

tsql正常的情况下:

 $ tsql -S SERVER001 -U username -P password

返回:

 locale is "C/UTF-8/C/C/C/C"
 locale charset is "UTF-8"
 using default charset "UTF8"
 1> 

$ cat ~/.freetds.conf:

 [SERVER001]
   host = 192.168.8.101
   port = 1433
   tds version = 8.0
   client charset = UTF8

$ cat ~/.odbc.ini:

  [SMS_GTWY]
  Description = SERVER001 Server
  Driver      = freetds
  Database    = SMS_GTWY
  ServerName  = SERVER001
  TDS_Version = 7.1

$ cat ~/.odbcinst.ini:

  [freetds]
  Description = MS SQL database access with FreeTDS
  Driver      = /usr/local/lib/libtdsodbc.so
  Setup       = /usr/local/lib/libtdsodbc.so
  UsageCount  = 1

freetdsunixODBC由home brew安装.

freetds and unixODBC are install by homebrew.

我在CentOS上具有类似的设置,并且odbc isql与mssqlserver正常工作.有一个明显的区别,我看不到OS X上安装的libtdsS.so.

I have a similar setup on CentOS and odbc isql to mssqlserver is working fine. There is a noticable difference, I do not see a libtdsS.so installed on OS X.

# cat /etc/odbcinst.ini:

 [freetds]
 Description = MS SQL database access with FreeTDS
 Driver      = /usr/lib/libtdsodbc.so
 Setup       = /usr/lib/libtdsS.so 
 UsageCount  = 1

是问题的原因吗?

p.s. $ odbcinst -j返回:

 unixODBC 2.3.1
 DRIVERS............: /usr/local/Cellar/unixodbc/2.3.1/etc/odbcinst.ini
 SYSTEM DATA SOURCES: /usr/local/Cellar/unixodbc/2.3.1/etc/odbc.ini
 FILE DATA SOURCES..: /usr/local/Cellar/unixodbc/2.3.1/etc/ODBCDataSources
 USER DATA SOURCES..: /Users/horace/.odbc.ini
 SQLULEN Size.......: 8
 SQLLEN Size........: 8
 SQLSETPOSIROW Size.: 8

$ odbcinst -q -d返回:

 [freetds]

$ odbcinst -q -s返回:

 [SMS_GTWY]

推荐答案

isql在重新安装unixodbcfreetds(--with-unixodbc)后可以工作:

isql works after reinstall unixodbc and freetds ( --with-unixodbc ):

 brew uninstall freetds
 brew uninstall unixodbc

 brew install unixodbc
 brew install freetds --with-unixodbc

现在,$ isql -v SMS_GTWY username password返回:

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

信用: https://gist.github.com/565440

这篇关于odbc无法连接到OS X Lion上的MSSQL数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 06:38