繁体   English   中英

将SQL Server直接连接到在线数据库rails activerecord-sqlserver-adapter

[英]Connecting SQL-Server directly to online Database rails activerecord-sqlserver-adapter

我刚刚安装了[ README.md][1]文件中提到的两个gem。 我有一个查询字符串,我想直接从本地主机连接到数据库。是否可以?

class Timelapse < ActiveRecord::Base
  establish_connection({
    :adapter  => "sqlserver",
    :host     => "myhostname.net",
    :username => "myusername",
    :password => "mypassword",
    :database => "mydbname"
  })
end

我去了rails c试图做Timelapse.first并得到一个错误是

TinyTds::Error: Adaptive Server connection failed
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/tiny_tds-0.7.0/lib/tiny_tds/client.rb:74:in `connect'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/tiny_tds-0.7.0/lib/tiny_tds/client.rb:74:in `initialize'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/connection_adapters/sqlserver_adapter.rb:311:in `new'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/connection_adapters/sqlserver_adapter.rb:311:in `dblib_connect'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/connection_adapters/sqlserver_adapter.rb:302:in `connect'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/connection_adapters/sqlserver_adapter.rb:58:in `initialize'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/sqlserver_base.rb:17:in `new'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/sqlserver_base.rb:17:in `sqlserver_connection'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
    from /home/ijunaidfarooq/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
    from /home/ijunaidfarooq/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:87:in `connection'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/querying.rb:39:in `find_by_sql'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/relation.rb:639:in `exec_queries'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/relation.rb:515:in `load'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/relation.rb:243:in `to_a'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.6/lib/active_record/relation.rb:630:in `inspect'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /home/ijunaidfarooq/.rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:8:in `require'

使用这些宝石像这样连接

setp:-1个gem'tiny_tds'gem'activerecord-sqlserver-adapter'

并检查git activerecord-sqlserver-adapter

步骤:-2开发:端口:1433模式:dblib适配器:sqlserver主机:#当dataserver为空时使用数据库:用户名:密码:超时:0

默认端口:1433#默认为1433默认模式:dblib数据服务器:超时:5000超时:0-无超时天蓝色:true
DSN:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM