Подключение к нескольким БД Rails, SQLite3 и SQLServer 2008 - PullRequest
1 голос
/ 09 марта 2012

Я пытаюсь подключиться к серверу SQL под названием Demand, используя этот гем: https://github.com/rails-sqlserver/I'm

Я следую рецепту №3 из книги «Рельсовые рецепты» http://pragprog.com/book/rr2/rails-recipes

Вот мой файл 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 хороши, так как я сейчас подключен через жабу, также создал модель 'Demand', чтобы у рельсов был объект)

> 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

1 Ответ

1 голос
/ 12 марта 2012

Я обнаружил, что, поскольку пароль пользователя внешней БД начинался с символа @, 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 >
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...