0

I'm attempting to establish an Active Record connection with my ruby script and I keep getting the following error:

Traceback (most recent call last):
        10: from ./main.rb:2:in `<main>'
         9: from /home/daveomcd/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
         8: from /home/daveomcd/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
         7: from /mnt/c/Users/mcdonaldd/Documents/Ruby Projects/nfl_ngs/config/initializers/initializer.rb:17:in `<top (required)>'
         6: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_handling.rb:60:in `establish_connection'
         5: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:950:in `establish_connection'
         4: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/connection_specification.rb:190:in `spec'
         3: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/connection_specification.rb:203:in `rescue in spec'
         2: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/connection_specification.rb:203:in `raise'
         1: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/connection_specification.rb:203:in `exception'
/home/daveomcd/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/errors.rb:84:in `initialize': wrong number of arguments (given 1, expected 2) (ArgumentError)

My files for connection are listed below, I'm not sure what I'm doing incorrectly.

require 'active_record'
require 'tiny_tds'
require 'rubygems'
require 'json'
require 'pp'
require 'yaml'
require 'base64'
require 'uri'
require 'net/http'
require 'openssl'
require 'byebug'

# commented out and hard coded while debugging    
#@dbconfig = YAML.load(File.read("./config/database.yml"))
ActiveRecord::Base.establish_connection(
    adapter: 'sqlserver',
    host: '10.xxx.xxx.xx',
    post: '1433',
    database: 'mydb',
    username: '***',
    password: '***'
)
2
  • 1
    what is the actual error? You left this part off of the stack trace. Also you need to require activerecord-sqlserver-adapter to use it tiny_tds is not enough Commented Aug 24, 2018 at 14:26
  • @engineersmnky, thanks my issue was I didn't have the require for 'activerecord-sqlserver-adapater' If you would like to submit an answer in regards to that I'll mark it. Thanks! Commented Aug 24, 2018 at 14:54

2 Answers 2

1

ActiveRecord connections require connections adapters to transform the SQL appropriately to suit the database AR is interacting with. ActiveRecord ships with a set of native adapters including "mysql2","postgres", and "sqlite3", however in this case you are using MSSQL (as indicated by adapter: 'sqlserver' in your connection configuration) which will require an external adapter.

The external adapter in this case is the activerecord-sqlserver-adapter gem.

This can be installed using gem install activerecord-sqlserver-adapter and then you just need to require it in your file as you have done with the other gems.

While this gem has no explicit dependencies (outside of ActiveRecord) you will need to specify a connection mode (or use the default :dblib). Using the default is by far the easiest route (and I have never had any issues with it), however this mode does require the inclusion of the tiny_tds gem (which you have already required)

Sign up to request clarification or add additional context in comments.

Comments

0

Probably, you must install activerecord-sqlserver-adapter as our friend says. By default, ruby on rails come with sqlite. Try install rubymine IDE, it will help you configure a database using an interface. Look at below:

Configuration screen

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.