mardi 28 novembre 2017

ActiveRecord::StatementInvalid: TinyTds::Error: Invalid column prefix '': No table name specified

How to access data in rails console. I have establish_connection on another database. When i try to access data console. like this i got error.

Checkinout.all
  SQL (645.2ms)  USE [ZKA]
  Checkinout Load (45.0ms)  EXEC sp_executesql N'SELECT .* FROM '
TinyTds::Error: Invalid column prefix '': No table name specified: EXEC sp_executesql N'SELECT .* FROM '
ActiveRecord::StatementInvalid: TinyTds::Error: Invalid column prefix '': No table name specified: EXEC sp_executesql N'SELECT .* FROM '

I have use gem:

gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter'

In my database.yml

development_sec:
  mode: dblib
  adapter: sqlserver
  host: ***.***.**.**
  database: ABC
  username: sa
  password: pass
  port: 1433

Migration

class CreateCheckinouts < ActiveRecord::Migration
  ActiveRecord::Base.establish_connection("development_sec")
  def change
    create_table :checkinouts do |t|

      t.timestamps null: false
    end
  end
  ActiveRecord::Base.establish_connection(Rails.env)
end

model/checkinout.rb

class Checkinout < ActiveRecord::Base
    establish_connection "#{Rails.env}_sec"
end

Aucun commentaire:

Enregistrer un commentaire