Have you ever had to connect to SQL Server with ActiveRecord? Is this possible? Can anyone provide some starting points?
This what I used: From here: http://github.com/rails-sqlserver/2000-2005-adapter/tree/master Installation First, you will need Ruby DBI and Ruby ODBC. To my knowledge the ADO DBD for DBI is no longer supported. The installation below is not a comprehensive walk thru on how to get all the required moving parts like FreeTDS installed and/or configured. It will also assume gem installations of both the dependent libraries and the adapter itself. It should be noted that this version of the adapter was developed using both the ancient 0.0.23 version of DBI up to the current stable release of 0.4.0. Because later versions of DBI will be changing many things, IT IS HIGHLY RECOMMENDED that you max your install to version 0.4.0 which the examples below show. For the time being we are not supporting DBI versions higher than 0.4.0. The good news is that if you were using a very old DBI with ADO, technically this adapter will still work for you, but be warned your path is getting old and may not be supported for long.
From here: http://lambie.org/2008/02/28/connecting-to-an-mssql-database-from-ruby-on-ubuntu/ Firstly, update your ~/.profile to include the following:
Then reload your .profile, by logging out and in again. Secondly, on Ubuntu 7.10 Server I needed to install some packages.
With FreeTDS installed I could configure it like this:
The important thing here is ACUMENSERVER, which is the DSN that I’ll use when connecting to the database. The host, and port are self-explanatory, and it’s worth noting that I had to use 7.0 specifically as the tds version. Testing FreeTDS is not too hard:
Next up it’s necessary to configure ODBC:
I then tested the connection with isql:
OK, so we’ve got ODBC using FreeTDS to connect to a remote MSSQL server. All that’s left is to add Ruby into the mix.
The last thing to test is that Ruby can use DBI and ODBC to hit the actual database, and that’s easy to test:
And a more complete test (only with SQL SELECT, mind you):
From here (to fix the odbc lib being in the wrong place): http://ubuntuforums.org/showthread.php?t=433435&page=2
either way works when accessing mssql from the prompt
i found this to be useful http://www.unixodbc.org/doc/FreeTDS.html#Configuration And then in the database.yml file:
|
|||
|
These are the steps i've compiled for Centos 5.3. It took me a lot of trial and error to get this working. It's from a completely clean Centos installation. Install EPEL:
Install ruby, rubygems, freetds, unixODBC, development tools:
Install rails:
Install DB related gems:
Download, build and install ruby-odbc:
Final gem list:
You can use various tools like isql to test your ODBC connection. Brian's post covers this in nice detail so I won't repeat. In rails you need a database.yml that looks something like this:
|
|||
|
On Ubuntu, I use FreeTDS and the activerecord-sqlserver-adapter gem. You can install FreeTDS through apt:
And add this to your Gemfile:
I had to change the configured FreeTDS version number in
|
|||
|