加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 06:38:02 所属栏目: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
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读