# Using isql from rails app

**URL:** <https://www.ruby-forum.com/t/using-isql-from-rails-app/103302>\
**Category:** Rails\
**Created:** [May 3, 2007, 11:59pm UTC](https://www.ruby-forum.com/t/using-isql-from-rails-app/103302 "2007-05-03T23:59:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anitawa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/779978/32.png) [@anitawa](https://www.ruby-forum.com/u/anitawa)\
**Post date:** [May 3, 2007, 11:59pm UTC](https://www.ruby-forum.com/t/using-isql-from-rails-app/103302/1 "2007-05-03T23:59:14Z")

</div>

Hi,

Im new to rails and was wondering if someone can help me.  
I have a sybase database on a remote machine.

I want to get information from that db into my rails app using isql.

I can do it from the shell, but how do i do it from a rails app?

thanks in advance

---

<div class="post-metadata">

**Author:** ![anitawa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/779978/32.png) [@anitawa](https://www.ruby-forum.com/u/anitawa)\
**Post date:** [May 4, 2007, 12:31am UTC](https://www.ruby-forum.com/t/using-isql-from-rails-app/103302/2 "2007-05-04T00:31:18Z")

</div>

Hmmm, I don’t know anything about isql, but two possibilities stand  
out.

If this is a once-in-a-while administrative task, you could create a  
rake task (I really like this tutorial for that:  
[Using the Rake Build Language](http://www.martinfowler.com/articles/rake.html))

On the other hand, you could create a script in lib and bootstrap  
rails to it. The template code I’ve been using to get the rails  
environment ready is:

#!/usr/bin/env ruby

# Ensure the environment was specified

if ARGV.length != 1  
puts “usage: ruby file\_name.rb \<rails\_env\>”  
exit 1  
end

$LOAD\_PATH \<\< File.expand\_path(File.dirname( **FILE** ))

ENV[‘RAILS\_ENV’] = ARGV.first || ENV[‘RAILS\_ENV’]

require File.dirname( **FILE** ) + ‘/…/config/boot’  
require “#{RAILS\_ROOT}/config/environment”

def connect(environment)  
conf = YAML::load(File.open(File.dirname( **FILE** ) + ‘/…/config/  
database.yml’))  
ActiveRecord::Base.establish\_connection(conf[environment])  
end

# Open ActiveRecord connection

connect(ARGV.first)

At this point, you’ve got Rails running. You’ll want to have included  
any libraries necessary to use isql. Then, you’re just writing ruby  
code between isql and rails.

Good luck.

David R.

---

<div class="post-metadata">

**Author:** ![anitawa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/779978/32.png) [@anitawa](https://www.ruby-forum.com/u/anitawa)\
**Post date:** [May 4, 2007, 12:41am UTC](https://www.ruby-forum.com/t/using-isql-from-rails-app/103302/3 "2007-05-04T00:41:18Z")

</div>

Oh, btw, I forgot to mention. If you take the second approach–a lib/  
file\_name.rb approach to this, you’d just dump that in your crontab  
and call it regularly.

If you needed to just access your information at runtime through  
rails, you’d put something in environment.rb to tell rails how to  
access isql, but then you’d be on your own for actually doing  
something with that connection.

Hope this helps,

David R.
