尝试在Vagrant中将SQL Server与RoR应用程序连接时出错

时间:2019-04-23 23:10:28

标签: ruby-on-rails sql-server debian vagrant tiny-tds

我正在尝试将RoR应用程序与SQL Server连接。我创建了一个didUpdateValueFor文件,如下所示:

database.yml

我已启用TPC / IP,并在SQL Configuration Manager中将端口更改为1434。

当我尝试使用development: <<: *default adapter: sqlserver host: 'pcname\domain' encoding: 'unicode' database: 'db_name' username: 'user' password: 'pass' pool: 5 port: 1434 运行迁移时,控制台抛出:

  

TinyTds :: Error:在配置文件中找不到服务器名称

我以前已经安装了FreeTDS。而且我尝试了使用rake db:migratedataserver: 'pcname\domain:1434'而不使用端口

完整跟踪

dataserver: 'pcname\domain'

流浪文件

/home/vagrant/.rvm/gems/ruby-2.3.3/gems/tiny_tds-2.0.0/lib/tiny_tds/client.rb:54:in connect'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/tiny_tds-2.0.0/lib/tiny_tds/client.rb:54:ininitialize' /home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-sqlserver-adapter-5.2.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:375:in new'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-sqlserver-adapter-5.2.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:375:indblib_connect' /home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-sqlserver-adapter-5.2.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:361:in connect'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-sqlserver-adapter-5.2.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:59:ininitialize' /home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-sqlserver-adapter-5.2.0/lib/active_record/sqlserver_base.rb:13:in new'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-sqlserver-adapter-5.2.0/lib/active_record/sqlserver_base.rb:13:insqlserver_connection' /home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in new_connection'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:incheckout_new_connection' /home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in try_to_checkout_new_connection'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:inacquire_connection' /home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in checkout'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:inconnection' /home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in retrieve_connection'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:inretrieve_connection' /home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in connection'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:172:inmigrate'/home/vagrant/.rvm/gems/ruby-2.3.3/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:60:in block (2 levels) in <main>'
/home/vagrant/.rvm/gems/ruby-2.3.3/gems/rake-12.3.2/exe/rake:27:in' /home/vagrant/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in eval'
/home/vagrant/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in' Tasks: TOP => db:migrate

1 个答案:

答案 0 :(得分:0)

据我所知,您没有在无用的VM和主机之间转发任何端口,而对于在VM上运行的RoR,它需要执行此操作才能连接到SQL Server的端口。在主机上运行。在流浪者文件中添加以下行:

config.vm.network "forwarded_port", guest: 1434, host: 1434

,您可能还需要取消注释此行,以便可以访问RoR网站:

config.vm.network "forwarded_port", guest: 80, host: 8080

或将上面的端口更改为您在其上运行RoR的任何端口(我相信默认端口为3000,因此3000而非80