Friday, October 17, 2008

Easy Way to Configure Rails ActiveRecord and SQL Server on Mac OS X

Thanks to How to Connect To Microsoft SQL Server From Rails On OSX, I found out a very easy way to configure the database connection.

Assuming you have FreeTDS installed (easily through macports) and iODBC (comes out of the box with Mac OS X) then this is all you need in your database.yml file:


development:
adapter: sqlserver
mode: odbc
dsn: DRIVER=/opt/local/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=10.0.6.20;DATABASE=awesome_development;Port=1433;uid=sa;pwd=password;


No configuration of a DSN required, and no mucking about with freetds.conf!

Now, if I could just use database.yml to get rid of SQL Server all together, I'd be a happy developer.

4 comments:

Hugh Williams said...

Note the same is true for other ODBC accessible databases using the same DSN-less connection support mechanism added for Rails 1.5 and 2.x as detailed at:

http://odbc-rails.rubyforge.org/RailsAdapterWebGeneralInformation.html

Peter Daly said...

"Now, if I could just use database.yml to get rid of SQL Server all together, I’d be a happy developer."

EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"

Problem solved. ;-)

Hugh Williams said...

Note the same is true for other ODBC accessible databases using the same DSN-less connection support mechanism added for Rails 1.5 and 2.x as detailed at:

http://odbc-rails.rubyforge.org/RailsAdapterWebGeneralInformation.html

Peter Daly said...

"Now, if I could just use database.yml to get rid of SQL Server all together, I’d be a happy developer."

EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"

Problem solved. ;-)