sql-server – odbc无法连接到OS X Lion上的MSSQL数据源

前端之家收集整理的这篇文章主要介绍了sql-server – odbc无法连接到OS X Lion上的MSSQL数据源前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
odbc isql无法连接到数据源:
$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

freetds和unixODBC由homebrew安装.

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

CentOS上的#cat /etc/odbcinst.ini:

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

这是问题的原因吗?

附: $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]

解决方法

重新安装unixodbc和freetds(–with-unixodbc)后isql正常工作:
brew uninstall freetds
 brew uninstall unixodbc

 brew install unixodbc
 brew install freetds --with-unixodbc

现在,$isql -v SMS_GTWY用户名密码返回:

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

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

原文链接:https://www.f2er.com/mssql/78432.html

猜你在找的MsSQL相关文章