# Connecting to SQL Server 2005

**URL:** <https://www.ruby-forum.com/t/connecting-to-sql-server-2005/192818>\
**Category:** Ruby\
**Created:** [August 6, 2010, 9:49am UTC](https://www.ruby-forum.com/t/connecting-to-sql-server-2005/192818 "2010-08-06T09:49:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![parulg2386](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@parulg2386](https://www.ruby-forum.com/u/parulg2386)\
**Post date:** [August 6, 2010, 9:49am UTC](https://www.ruby-forum.com/t/connecting-to-sql-server-2005/192818/1 "2010-08-06T09:49:20Z")

</div>

I need to connect to SQL server 2005 using Ruby. I went through some  
posts but did not found much help.  
It would be great if anyone can help me with this.

---

<div class="post-metadata">

**Author:** ![parulg2386](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@parulg2386](https://www.ruby-forum.com/u/parulg2386)\
**Post date:** [August 6, 2010, 2:36pm UTC](https://www.ruby-forum.com/t/connecting-to-sql-server-2005/192818/2 "2010-08-06T14:36:26Z")

</div>

Parul K. wrote:

> I need to connect to SQL server 2005 using Ruby. I went through some  
> posts but did not found much help.  
> It would be great if anyone can help me with this.

ODBC is the way.

Linux: Search for “odbc freetds ruby mssql” in google.

Windows: I use DBI with ODBC support. Should not be trouble searching on  
google. Here is something to start from.

require ‘dbi’  
dbh = DBI.connect(‘DBI:ODBC:Driver={SQL Server};  
Server=MYSQL2005;Database=mydb;Uid=myusr;Pwd=mypwd’)

dbh.select\_all(“select \* from some\_table”) do |r|  
somefield = r[2].downcase  
end  
dbh.disconnect

by  
TheR

---

<div class="post-metadata">

**Author:** ![parulg2386](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@parulg2386](https://www.ruby-forum.com/u/parulg2386)\
**Post date:** [August 6, 2010, 4:03pm UTC](https://www.ruby-forum.com/t/connecting-to-sql-server-2005/192818/3 "2010-08-06T16:03:51Z")

</div>

if your are working with rails you can try

> **[GitHub - rails-sqlserver/activerecord-sqlserver-adapter: SQL Server Adapter...](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter)**
>
> SQL Server Adapter For Rails. Contribute to rails-sqlserver/activerecord-sqlserver-adapter development by creating an account on GitHub.

## [http://github.com/rails-sqlserver/activerecord-sqlserver-adapter](http://github.com/rails-sqlserver/activerecord-sqlserver-adapter)

Allan D.  
[http://codesnakes.blogspot.com](http://codesnakes.blogspot.com) (my blog)  
[http://www.linkedin.com/in/javaalley](http://www.linkedin.com/in/javaalley)
