VirtualBoxを使用してUbuntu 11.10 vmが実行されているWindows 7マシンがあります。私のWindows 7マシンにはSQL Server 2008がインストールされており、rails 3.2とtiny_tds gemを使用してUbuntu vmからアクセスしようとしています。
Rails アプリケーションを起動しようとすると、次のようになります。
/home/user/.rvm/gems/ruby-1.9.3-p0/gems/tiny_tds-0.5.1/lib/tiny_tds/client.rb:68:in `connect': Unable to open socket (TinyTds::Error)
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/tiny_tds-0.5.1/lib/tiny_tds/client.rb:68:in `initialize'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-sqlserver-adapter-3.2.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:415:in `new'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-sqlserver-adapter-3.2.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:415:in `connect'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-sqlserver-adapter-3.2.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:203:in `initialize'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-sqlserver-adapter-3.2.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:40:in `new'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-sqlserver-adapter-3.2.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:40:in `sqlserver_connection'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:277:in `new_connection'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:287:in `checkout_new_connection'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:235:in `block (2 levels) in checkout'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `loop'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `block in checkout'
from /home/user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:308:in `clear_cache!'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/railtie.rb:91:in `block (2 levels) in <class:Railtie>'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:418:in `_run__855141609__prepare__585695355__callbacks'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.1/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.1/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instance_exec'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/application.rb:136:in `initialize!'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/user/RubymineProjects/myapp/config/environment.rb:5:in `<top (required)>'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
from /home/user/RubymineProjects/myapp/config.ru:4:in `block in <main>'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /home/user/RubymineProjects/myapp/config.ru:1:in `new'
from /home/user/RubymineProjects/myapp/config.ru:1:in `<main>'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/server.rb:46:in `app'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/server.rb:70:in `start'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
from /home/user/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
ポート 1433 でホスト IP に telnet を実行することにより、SQL Server が vm にアクセスできることを確認でき、正常に接続できますが、何らかの理由で ruby または TinyTds 経由で接続できません。VM のネットワーク アダプタは NAT を使用しています。さらに、同じ Rails アプリケーションを Windows マシンから実行すると、SQL Server に接続できます。TCP/IP 接続が SQL Server に対して有効になっています。