This connects to MSSQL server ( 2000 I think ) using OLE

Be warned, ole ( or rubys bindings to it ) leaks like a sieve

require 'dbi'


DB = "Provider=SQLOLEDB.1;Password=secret;Persist Security Info=True;User 
ID=admin;Initial Catalog=my_database;Data Source=the_server"




sql = " select distinct * from sometable"
DBI.connect("DBI:ADO:#{DB}") do | dbh |
    dbh.select_all( sql ) do |row|
        puts row[0]  # the first field
        puts row[1]  # the second field
    end        
end


You may need to install the ADO driver separately, but odbc would work in the 
same way as above, just 
the lines with
DBI:ADO:....
 and 
DB='..'
would be different




----- Original Message -----
From: Ethan Jewett <[EMAIL PROTECTED]>
Date: Tuesday, February 6, 2007 3:42 pm
Subject: Re: [Wtr-general] How do I connect to MS SQL 2005 using Ruby?

> As mentioned in a thread going on at the same time as this one,
> ActiveRecord is not Rails.  It can be run alone and can be installed
> as a gem ("gem install activerecord").  I suppose it could be
> considered a rail, or maybe a tie . . .
> 
> In any case, it does have an SQLServer adapter.  See
> http://api.rubyonrails.com/classes/ActiveRecord/ConnectionAdapters/SQLServerAdapter.html
> for available methods and some compatibility caveats.
> 
> If you are dead-set against running ActiveRecord, it might still be
> useful to check out how the adapter connects using WIN32OLE and DBI.
> 
> Ethan
> 
> On 2/6/07, Nathan <[EMAIL PROTECTED]> wrote:
> > Right, I've already tried Google with several variations and 
> nothing there is what I'm looking for - I want to connect to MS 
> SQL WITHOUT rails, and this solution as well as every other 
> solution I've come across has been for rails, which requires a 
> rails server to be running.  I just want plain ruby - it looks 
> like maybe I can create an ODBC connection on windows, then 
> connect to that via DBI somehow, but I can't figure out the 
> connection string.  Does anybody know about this?
> >
> > Nathan
> > -----------------------------------------------------------------
> ----
> > Posted via Jive Forums
> > 
> http://forums.openqa.org/thread.jspa?threadID=6445&messageID=18257#18257> 
> _______________________________________________
> > Wtr-general mailing list
> > [email protected]
> > http://rubyforge.org/mailman/listinfo/wtr-general
> >
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
> 
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to