我无法从这个非常简单的 Ruby 应用程序连接到 SQL Server 2005 安装:
#!/usr/bin/env ruby
require 'rubygems'
require 'sequel'
Sequel.odbc('dev04')['select top 1 * from users'].all
dev04
DSN 指向我的文件odbc.ini
条目:
[dev04]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
Trace = 1
Servername = dev04
Database = Dev04
UID = uDev04
PWD = pwdDev04
FreeTDS
安装在 odbcinst.ini 中,它指向以下配置freetds.conf
:
[dev04]
host = hm602.mycompany.com
port = 1433
tds version = 7.0
这有效:
carlos$ tsql -S dev04 -U uDev04 -P pwdDev04
locale is "en_GB.UTF-8"
locale charset is "UTF-8"
1> exit
carlos$
这也是如此:
carlos$ iodbctest "DSN=dev04;UID=uDev04;PWD=pwdDev04"
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.0406.1211
Driver: 0.82 (libtdsodbc.so)
SQL>exit
Have a nice day.
carlos$
但是,当我运行那个 Ruby 脚本时,我得到了这个错误:
carlos$ ruby mssql.rb
/Library/Ruby/Gems/1.8/gems/sequel-3.4.0/lib/sequel/adapters/odbc.rb:37:in `initialize': ODBC::Error 01000 (20002) [FreeTDS][SQL Server]Adaptive Server connection failed (Sequel::DatabaseConnectionError)
from /Library/Ruby/Gems/1.8/gems/sequel-3.4.0/lib/sequel/adapters/odbc.rb:37:in `connect'
from /Library/Ruby/Gems/1.8/gems/sequel-3.4.0/lib/sequel/adapters/odbc.rb:37:in `connect'
from /Library/Ruby/Gems/1.8/gems/sequel-3.4.0/lib/sequel/database.rb:92:in `initialize'
...
我了解由于 TDS 协议版本差异可能会出现“自适应服务器连接失败”错误。我检查了日志,它们似乎都使用了正确的版本(7.0),所以我完全不知道为什么会发生这种情况。
任何指针?