ActiveRecord连接建立,但为什么没有连接

时间:2014-02-04 14:28:27

标签: ruby activerecord

我正在更新我的ruby套件上的ActiveRecord(一个非常需要的升级),我遇到了数据库连接问题。它在ActiveRecord :: Base.establish_connection调用上似乎没有失败,但是当我连接时?方法它返回false。我已经包含了我正在传递给establish_connection方法的哈希值(我已经验证了工作的网址,用户名和密码)和我的连接?调用

puts "establishing connection to #{config[env]}"
@db_connection = ActiveRecord::Base.establish_connection(config[env])
puts "database connected? #{@db_connection.connected?}"

输出:

establishing connection to {"adapter"=>"jdbc", "driver"=>"oracle.jdbc.driver.OracleDriver", "url"=>"my_url","username"=>"my_username", "password"=>"my_password"}

database connected? false

编辑:连接方法

  def connect(env)
    begin
    config = YAML.load_file("features/config/servers.yml")
    rescue
      puts "cannot load config/servers.yml"
    end
    puts "establishing connection to #{config[env]}"
    @db_connection = ActiveRecord::Base.establish_connection(config[env])
    puts @db_connection.connected?
    puts "connected to #{config[env]}"
  end

数据库YML

  adapter: jdbc
  driver: oracle.jdbc.driver.OracleDriver
  url: jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host_ip_address)(PORT=host_port_number))(CONNECT_DATA=(UR=A)(SERVICE_NAME=database_name)))
  username: my_username
  password: My_Password

0 个答案:

没有答案