Skip to content

Instantly share code, notes, and snippets.

@trekr5
Created November 19, 2015 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trekr5/3e09839090b51f76c034 to your computer and use it in GitHub Desktop.
Save trekr5/3e09839090b51f76c034 to your computer and use it in GitHub Desktop.
connetc to sql server db
require 'tiny_tds'
require 'active_record'
require 'activerecord-sqlserver-adapter'
require 'logger'
ActiveRecord::Base.pluralize_table_names = false
ActiveRecord::Base.establish_connection(
:adapter => 'sqlserver',
:database => 'myDB',
:username => 'trekr5',
:password => 'password',
:host => 'myhost.com'
)
# class Table < ActiveRecord::Base
# def self.test
query = <<-SQL
DECLARE @FundraiserId INT
SET @FundraiserId = 250942
PRINT @FundraiserId
SQL
results = ActiveRecord::Base.connection.select_all(query)
p results
results.each do |row|
p row
end
@trekr5
Copy link
Author

trekr5 commented Nov 19, 2015

When i test the connection, I get a value of -1 and when I iterate through the results, I get an empty array [] which is wrong because I should see the value of @FundraiserId which is 250942.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment