SQL SERVER 2008 problem

67 views
Skip to first unread message

randy bahalla

unread,
Apr 10, 2016, 8:05:32 PM4/10/16
to Rails SQLServer Adapter
Hi I'm new to ROR and developing an app that uses SQL SERVER 2008.
Already downgraded my rails to 4.1 and also using tiny_tds and activerecord-sqlserver-adapter

gem 'rails', '4.1'
gem
'tiny_tds'
gem
'activerecord-sqlserver-adapter'

I have this Model

class IpProject < ActiveRecord::Base
 
self.table_name = 'IP_Projects'
 
self.primary_key = "ProjectID"
end

when I try

IpProject.count

it returns the count of all rows which is correct and it shows that I can connect to the database but when I try to fetch the data, it is null.

IpProject.first

the above code returns #<IpProject:0x76397a0> and at first I thought it was an object so I tried to extract the data but I have no luck.
And then I tried to get the column names of my Model.

IpProject.columns

IpProject.column_names

both return []

I tried doing
ActiveRecord::Base.connection.exec_query("SELECT * FROM ip_projects").first

client.execute("SELECT * FROM ip_projects").first

and both returned the same correct data.

Am I missing something?

Touhidur Rahman

unread,
May 24, 2016, 7:52:57 AM5/24/16
to Rails SQLServer Adapter
Hi randy bahalla,

Use schema type of the tables in the model. As for examples -

class IpProject < ActiveRecord::Base
 
self.table_name = 'dbo.IP_Projects'
 
self.primary_key = "ProjectID"
end

OR

class IpProject < ActiveRecord::Base
 
self.table_name = 'db_owner.IP_Projects'
 
self.primary_key = "ProjectID"
end

You need to find the schema types(dbo or db_owner) of the tables first.

regards
Touhid
Reply all
Reply to author
Forward
0 new messages