Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Select table names from SQL Server from a Mac via ActiveRecord and TinyTDS driver
# Example Microsoft SQL Server
host = host
port = 1433
tds version = 8.0
require 'rubygems'
gem 'tiny_tds'
gem 'activerecord'
gem 'activerecord-sqlserver-adapter'
require 'active_record'
require 'logger'
logger =
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']}"

ejstembler commented Jan 19, 2012

Change host in freetds.conf to your host name of the I.P. address of the host. Also, change :database, :username, and :password in ss_ar_tinytds_test.rb accordingly.

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