如何使用Rails中的rake任务连接到SQL Server?

时间:2015-02-09 05:54:29

标签: ruby-on-rails ruby sql-server rails-activerecord

我尝试使用ActiveRecord sqlserver adapter连接到远程SQL Server视图:

@connection = ActiveRecord::Base.establish_connection(
  :adapter => "sqlserver",
  :dsn => "rms",
  :hosts => "xxx.xxx.xx.xx",
  :database => "V_MLS_ECOMM_STORE_SOH",
  :ports => "1521",
  :username =>  "xxxxxx",
  :passwords => "xxxxxxx")

@connection.connected?始终返回false。

1 个答案:

答案 0 :(得分:0)

做这样的事情:

class LegacyTable < ActiveRecord::Base
  establish_connection({
    :adapter  => "sqlserver",
    :host     => "host",
    :username => "user",
    :password => "pass",
    :database => "dbname"
  })

参考:https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/250