我正在尝试使用此gem连接到名为Demand的SQL服务器: https://github.com/rails-sqlserver/I'M
我正在遵循“Rails Recipes”http://pragprog.com/book/rr2/rails-recipes
一书中的食谱#3这是我的database.yml文件:
demand:
adapter: sqlserver
host: 172.21.148.01
port: 1433
database: Demand
username: DEapp
password: @pp1user
timeout: 5000
从rails控制台,当我用Demand.connection
测试连接时,我得到以下内容:
(我知道addy和pw很好,因为我现在通过toad连接,也创建了模型'Demand'所以rails会有一个对象)
> TinyTds::Error: Login failed for user ‘DEapp’. from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/tiny_tds-0.5.1/lib/tiny_tds/client.rb:68:in
> `connect’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/tiny_tds-0.5.1/lib/tiny_tds/client.rb:68:in
> `initialize’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-sqlserver-adapter-3.1.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:400:in
> `new’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-sqlserver-adapter-3.1.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:400:in
> `connect’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-sqlserver-adapter-3.1.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:198:in
> `initialize’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-sqlserver-adapter-3.1.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:35:in `new’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-sqlserver-adapter-3.1.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:35:in `sqlserver_connection’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:304:in
> `new_connection’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:323:in
> `checkout_new_connection’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in
> `block (2 levels) in checkout’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in
> `loop’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in
> `block in checkout’ from
> /Users/drewgilliam/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in
> `mon_synchronize’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:260:in
> `checkout’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:162:in
> `connection’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:409:in
> `retrieve_connection’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in
> `retrieve_connection’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection’ from (irb):11 from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in
> `start’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in
> `start’ from
> /Users/drewgilliam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands.rb:40:in
> `‘ from script/rails:6:in `require’
有任何帮助吗?如果你也想在那里回答,那么这是Pragmatic Programmer论坛:http://forums.pragprog.com/forums/189/topics/10476
答案 0 :(得分:1)
我发现因为外部数据库用户密码是以@
符号开头的,所以rails并不满意,因为它认为它是实例变量。
我将PW更改为无法@
启动的内容,并且连接正常。
Drews-MacBook-Air:DE_App drewgilliam$ rails console
Loading development environment (Rails 3.1.3)
1.9.2p290 :001 > Externaldb.connection
EXECUTE (36.7ms) USE [DemandEstimator]
=> #<ActiveRecord::ConnectionAdapters::SQLServerAdapter version: 3.1.6, year: 2008, product_level: "SP1", product_version: "10.50.2500.0", edition: "Enterprise Edition (64-bit)", connection_options: {:adapter=>"sqlserver", :host=>"172.21.148.01", :port=>1433, :database=>"DemandEstimator", :username=>"DEapp", :password=>"demand_app_user", :timeout=>5000, :mode=>:dblib}>
1.9.2p290 :002 >