Select table names from SQL Server from a Mac via ActiveRecord and TinyTDS driver
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
Change host in freetds.conf to your host name of the I.P. address of the host. Also, change :database, :username, and :password in ssartinytds_test.rb accordingly.
Written by Edward J. Stembler
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Activerecord
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#