Created
November 19, 2015 17:34
-
-
Save trekr5/3e09839090b51f76c034 to your computer and use it in GitHub Desktop.
connetc to sql server db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.