Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to connect to MS SQL in Rails
    primarykey
    data
    text
    <p>I am attempting to migrate legacy data from a MS SQL database into my Rails Application. I have added configuration in freetds which is connecting properly. In my Gemfile, I have added the <a href="https://github.com/rails-sqlserver/tiny_tds" rel="nofollow">tiny_tds</a> and <a href="https://github.com/rails-sqlserver/activerecord-sqlserver-adapter" rel="nofollow">activerecord-sqlserver-adapter</a>, respectively. </p> <p>I have created a file to house the classes from the legacy database to translate to ActiveRecord:</p> <pre><code>class LegacyUser &lt; ActiveRecord::Base establish_connection :legacy set_table_name 'users' end . . . </code></pre> <p><strong>database.yml</strong></p> <pre><code>legacy: adapter: sqlserver mode: odbc dsn: legacy_db_name host: db_host_name database: legacy_db_name port: 1433 username: username password: password </code></pre> <p>Then I have rake tasks to convert the data:</p> <p><strong>legacy.rake</strong></p> <pre><code> desc 'migrate users' task :users =&gt; :environment do require 'lib/tasks/legacy_classes' LegacyUser.each do |user| begin new_user = User.new new_user.attributes = { :firstname =&gt; user.firstname, :lastname =&gt; user.lastname, :email =&gt; user.email, :created_at =&gt; Time.now, :updated_at =&gt; Time.now } new_user.save! puts "User #{user.id} successfully migrated" rescue puts "Error migrating #{user.id}" end end </code></pre> <p>At this point I am just trying to get the rake task to 'connect' to the legacy database.</p> <p>When I try 'rake users', I get:</p> <pre><code>rake aborted! database configuration does not specify adapter </code></pre> <p>It looks to me like I have clearly specified the adapter. What is the proper way to configure this? </p> <p>Also as a side question, in my 'classes' file for legacy database tables, should all of those tables mirror the 'new' Rails database schema? Ideally I want to be able to simply connect to various tables in the legacy database and fit them into the new database schema where needed. The associations in the old do not match the new, nor do the naming conventions. </p> <p>Any help is appreciated. Thanks.</p> <h2>Update</h2> <p>Still experiencing this error. Sadly, the only threads I could find that have had the same error were odd spacing issues in the database.yml file. So I actually took the time to go through and make sure all of the spacing matched my other configurations. Given that it is a vague error I am not really even sure what to check past the instructions for setting up activerecord-sqlserver-adapter. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload