Simple ruby ​​ODBC database connection

I am trying to make a simple connection to a remote database. I can't seem to get it to work.

remote_db = DBI.connect('DBI:ODBC:remote-host','user','password') remote_db.table { |table| pp table } 

Any help would be greatly appreciated.

+4
source share
1 answer

I think you are looking for Ruby DBI.
http://ruby-dbi.rubyforge.org/

The following is an example of using DBI to connect to ODBC:

 # Require in the DBI files<br /> require 'DBI' # create an ODBC connection instance<br /> dbi_conn = DBI.connect('DBI:ODBC:datasource','your_username','your_password') # query tables available <br /> dbi_conn.tables # returns an array with the results from a table TABLE:<br /> array_out = dbi_conn.select_all('SELECT * FROM TABLE') 

Additional Information:
http://www.kitebird.com/articles/ruby-dbi.html

Or, alternatively, you can use ruby-odbc:
http://odbc-rails.rubyforge.org/

+4
source

All Articles