Forum: Ruby Help with connecting to SQL Server 2005 Database with Ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Arti S. (Guest)
on 2009-05-06 19:04
I am quite new to ruby and trying to connect to a SQL Server 2005
Database with ruby  to run a few queries but I am not getting anywhere.
Am I missing something? I am getting a connection refused on all counts.

I have installed the following gems: DBI,WIN32OLE,SEQUEL

Below are some of the strings that I have tried to use

db=Sequel.connect(database=@dbase,  user=@user, pword=@pword,
hostdb=@dbase)

db = Sequel.connect('postgres://username:password@hostdb/database')

db=DBI.connect("DBI:ADO:Provider=SQLNCLI;Data Source=hostdb;Initial
Catalog=dbase;username=username;pword=password")


db=DBI.connect("DBI:ODBC:Driver={SQLServer};Server=hostdb;Database=dbase;Uid=username;Pwd=password")

db=DBI.connect('DBI:ODBC:hostdb',Database=@dbase,Data
Source=@hostdb,Uid=@user,Pwd=@pword)

db=DBI.connect("DBI:OLEDB:Provider=sqloledb;Data Source=@dbase;Initial
Catalog=@dbase;User Id=@user;Password=@pword")
Ben L. (Guest)
on 2009-05-06 19:20
(Received via mailing list)
On Wed, May 6, 2009 at 4:04 PM, Arti S. <removed_email_address@domain.invalid>
wrote:

> I am quite new to ruby and trying to connect to a SQL Server 2005
> Database with ruby  to run a few queries but I am not getting anywhere.
> Am I missing something? I am getting a connection refused on all counts.
>

Try this if you're using sequel:

DB = Sequel.ado('database_name', :host => 'localhost', :user =>
'username',
:password => 'password')

Should work if you replace the 'database_name', host, user and password
with
your own.

Ben
Arti S. (Guest)
on 2009-05-06 20:11
Thank you Ben. This works now.
This topic is locked and can not be replied to.