[英]How to connect MS SQL database to Ruby
我正在尝试将MS SQL数据库连接到我的Ruby程序,以运行只读查询。 我尝试使用Sequel,Ruby-DBI和TinyTDS无济于事。
这是我与Sequel连接的代码:
require 'rubygems'
require 'sequel'
hostname = 'DB name'
username = 'username here'
password = 'password here'
port = 1433
connection_instance = Sequel.connect(:host => hostname, :user => username, :password => password, :test => true)
这是我收到的错误:
C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
: LoadError: cannot load such file -- sequel/adapters/ (Sequel::AdapterNotFound)
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sequel-4.35.0/lib/sequel/database/connecting.rb:98:in `load_adapter'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sequel-4.35.0/lib/sequel/database/connecting.rb:28:in `adapter_class'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sequel-4.35.0/lib/sequel/database/connecting.rb:56:in `connect'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sequel-4.35.0/lib/sequel/core.rb:108:in `connect'
from snippet.rb:11:in `<main>'
我使用tinytds与:
@db = Sequel.tinytds(
:host => options['dbserver'],
:database=> options['db'],
:user => options['dbuser'],
:password=> options['dbpwd'],
#:timeout => options['timeout'], #for long lasting requests
)
过去我使用了ado,但是使用ado时遇到了一些问题(编码错误,超时...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.