Skip to content

Instantly share code, notes, and snippets.

@bosko
Created February 24, 2010 11:26
Show Gist options
  • Save bosko/313340 to your computer and use it in GitHub Desktop.
Save bosko/313340 to your computer and use it in GitHub Desktop.
List Databases
require 'activerecord-sqlserver-adapter'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlserver',
:mode => 'ODBC',
:host => '<server>',
:username => '<user_name>',
:password => '<pass>'
:dsn => '<odbc_dsn_name>'
)
databases = ActiveRecord::Base.connection.select_all('select name from sys.databases')
require "rubygems"
require "active_record"
require 'logger'
ActiveRecord::Base.establish_connection(
:adapter => 'postgresql',
:database => '<db_name>',
:username => '<user>',
:password => '<pass>',
:host => '/var/run/postgresql')
ActiveRecord::Base.logger = Logger.new('logfile.txt')
databases = ActiveRecord::Base.connection.query("select datname from pg_database")
#=> [["template1"], ["template0"], ["postgres"], ["testdb"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment