簡體   English   中英

如何將MS SQL數據庫連接到Ruby

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM