Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord::StatementInvalid (NoMethodError: undefined method `[]' for nil:NilClass: EXEC sp_executesql N'SELECT @@version'): #413

Open
iesartia opened this issue Mar 9, 2017 · 2 comments · May be fixed by #528

Comments

@iesartia
Copy link

iesartia commented Mar 9, 2017

I have Rails 4.2 and I have configured shards.yml file in following way:

octopus:
  environments:
    - development
  replicated: true
  fully_replicated: true
  verify_connection: true
  development:
    shard_1:
      adapter: sqlserver
      host: 192.168.100.116
      database: DB
      username: u
      password: p
    shard_2:
      adapter: sqlserver
      host: 192.168.100.116
      database: DB
      username: u
      password: p

I cannot connect to database, what I have missed?

ActiveRecord::StatementInvalid (NoMethodError: undefined method `[]' for nil:NilClass: EXEC sp_executesql N'SELECT @@version'):
  ar-octopus (0.9.0) lib/octopus/abstract_adapter.rb:22:in `octopus_shard'
  ar-octopus (0.9.0) lib/octopus/abstract_adapter.rb:12:in `instrument'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
  activerecord-sqlserver-adapter (4.2.15) lib/active_record/connection_adapters/sqlserver/database_statements.rb:311:in `raw_select'
  activerecord-sqlserver-adapter (4.2.15) lib/active_record/connection_adapters/sqlserver/database_statements.rb:260:in `sp_executesql'
  activerecord-sqlserver-adapter (4.2.15) lib/active_record/connection_adapters/sqlserver/database_statements.rb:19:in `exec_query'
  activerecord-sqlserver-adapter (4.2.15) lib/active_record/connection_adapters/sqlserver/database_statements.rb:215:in `select'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/database_statements.rb:38:in `select_one'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/database_statements.rb:43:in `select_value'
  activerecord-sqlserver-adapter (4.2.15) lib/active_record/connection_adapters/sqlserver_adapter.rb:59:in `initialize'
  activerecord-sqlserver-adapter (4.2.15) lib/active_record/sqlserver_base.rb:17:in `new'
  activerecord-sqlserver-adapter (4.2.15) lib/active_record/sqlserver_base.rb:17:in `sqlserver_connection'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
  /home/iliaesartia/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
  /home/iliaesartia/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
  ar-octopus (0.9.0) lib/octopus/proxy.rb:225:in `safe_connection'
  ar-octopus (0.9.0) lib/octopus/proxy.rb:232:in `select_connection'
  ar-octopus (0.9.0) lib/octopus/proxy.rb:303:in `method_missing'
  activerecord (4.2.7.1) lib/active_record/query_cache.rb:32:in `call'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.7.1) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
  activesupport (4.2.7.1) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
  activesupport (4.2.7.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.7.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.7.1) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.7.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.7.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.7.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.7.1) lib/rails/rack/logger.rb:20:in `call'
  request_store (1.3.2) lib/request_store/middleware.rb:9:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.5) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.5) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.7.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.5) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/static.rb:120:in `call'
  rack (1.6.5) lib/rack/sendfile.rb:113:in `call'
  rack-cors (0.4.0) lib/rack/cors.rb:80:in `call'
  railties (4.2.7.1) lib/rails/engine.rb:518:in `call'
  railties (4.2.7.1) lib/rails/application.rb:165:in `call'
  rack (1.6.5) lib/rack/content_length.rb:15:in `call'
  puma (3.6.2) lib/puma/configuration.rb:225:in `call'
  puma (3.6.2) lib/puma/server.rb:578:in `handle_request'
  puma (3.6.2) lib/puma/server.rb:415:in `process_client'
  puma (3.6.2) lib/puma/server.rb:275:in `block in run'
  puma (3.6.2) lib/puma/thread_pool.rb:116:in `block in spawn_thread'
@iesartia
Copy link
Author

iesartia commented Mar 9, 2017

@config[:octopus_shard] is null and it causes error, how to fix it?

@krzcho
Copy link

krzcho commented Apr 10, 2017

I am not totally sure but it may be activerecord-sqlserver-adapter working against sql server 2008 - it is 4.1 branch that seems to be the last one working with that version of sql server

calh added a commit to calh/octopus that referenced this issue Jun 26, 2019
Error message is:

ActiveRecord::StatementInvalid: NoMethodError: undefined method `[]' for
nil:NilClass:

  from octopus/lib/octopus/abstract_adapter.rb:23:in `octopus_shard'
  from octopus/lib/octopus/abstract_adapter.rb:12:in `instrument'
  from vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'

This has shown to surface in the ibm_db and sqlserver adapters.
@calh calh linked a pull request Jun 26, 2019 that will close this issue
calh added a commit to calh/octopus that referenced this issue Jun 26, 2019
Error message is:

ActiveRecord::StatementInvalid: NoMethodError: undefined method `[]' for
nil:NilClass:

  from octopus/lib/octopus/abstract_adapter.rb:23:in `octopus_shard'
  from octopus/lib/octopus/abstract_adapter.rb:12:in `instrument'
  from vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'

This has shown to surface in the ibm_db and sqlserver adapters.
calh added a commit to calh/octopus that referenced this issue Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants