# Help with connecting to SQL Server 2005 Database with Ruby

**URL:** <https://www.ruby-forum.com/t/help-with-connecting-to-sql-server-2005-database-with-ruby/167311>\
**Category:** Ruby\
**Created:** [May 6, 2009, 5:04pm UTC](https://www.ruby-forum.com/t/help-with-connecting-to-sql-server-2005-database-with-ruby/167311 "2009-05-06T17:04:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [May 6, 2009, 5:04pm UTC](https://www.ruby-forum.com/t/help-with-connecting-to-sql-server-2005-database-with-ruby/167311/1 "2009-05-06T17:04:21Z")

</div>

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”)

---

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [May 6, 2009, 5:20pm UTC](https://www.ruby-forum.com/t/help-with-connecting-to-sql-server-2005-database-with-ruby/167311/2 "2009-05-06T17:20:06Z")

</div>

On Wed, May 6, 2009 at 4:04 PM, Arti S. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [May 6, 2009, 6:11pm UTC](https://www.ruby-forum.com/t/help-with-connecting-to-sql-server-2005-database-with-ruby/167311/3 "2009-05-06T18:11:36Z")

</div>

Thank you Ben. This works now.
