https://gist.github.com/1642660
freetds.conf
# Example Microsoft SQL Server
[myTDS]
host = host
port = 1433
tds version = 8.0
ss_ar_tinytds_test.rb
require 'rubygems'
gem 'tiny_tds'
gem 'activerecord'
gem 'activerecord-sqlserver-adapter'
require 'active_record'
require 'logger'
logger = Logger.new(STDOUT)
ActiveRecord::Base.logger = logger
config = {
:adapter => 'sqlserver',
:mode => 'dblib',
:dataserver => 'myTDS', # defined in: /usr/local/etc/freetds.conf
:database => 'database',
:username => 'username',
:password => 'password'
}
ActiveRecord::Base.establish_connection config
sql = "select table_name from INFORMATION_SCHEMA.TABLES"
table_names = ActiveRecord::Base.connection.select_all sql
table_names.each do |h|
logger.debug "Table name = #{h['table_name']}"
end
Mude host em freetds.conf para o nome do host do endereço IP do host. Além disso, altere: banco de dados ,: nome de usuário e: senha em ss ar tinytds_test.rb de acordo.