Forum: Ruby on Rails ActiveRecord and tiny_tds

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bfa153a37248515bbf6d7a7bd49ba171?d=identicon&s=25 (Guest)
on 2013-12-17 13:06
(Received via mailing list)

I'm having some issues trying to run .find_by_sql against a Win MSSQL
server. When I use the tiny_tds gem the query works without any issues.

require 'rubygems'
gem 'tiny_tds', '= 0.6.2'
require 'tiny_tds'
gem 'activerecord', '= 3.2.12'
require 'active_record'
require 'activerecord-sqlserver-adapter'

client = => 'user',:password =>
=> 'host',:database => 'db')
result = client.execute(sql)
=> #<TinyTds::Result:0x000000022c3e48>

When I try the same query with an ActiveRecord::Base model I don't see
results (I've tried both :host and :dataserver with the same result).

class Ipdb < ActiveRecord::Base
        :adapter => "sqlserver",
        :host => 'host',
        :username => 'user',
        :password => 'pass',
        :database => 'db',
        self.table_name = "View_All_IPs"
ai = Ipdb.find_by_sql(sql)
p ai.size
=> 1
p ai.inspect
=>"[#<Ipdb >]"
p ai[0].class
=> Ipdb()
p ai[0]
=> #<Ipdb >

Any ideas about where the problem may be?

J-H Johansen
Bfa153a37248515bbf6d7a7bd49ba171?d=identicon&s=25 (Guest)
on 2013-12-17 16:14
(Received via mailing list)
After some more debugging I finally realized that the object actually
some data attached to it. It must have been the .inspect which fooled me
into thinking it was empty.

ai = Ipdb.where("[IP Address] = ?", ip)
ai.each do |b|
        puts b["IP Address"]
        puts b.Information

This outputs the information needed. Not sure why the object doesn't
all this information when I 'inspect' it...

kl. 13:05:07 UTC+1 tirsdag 17. desember 2013 skrev
This topic is locked and can not be replied to.