Search code examples
ruby-on-railssql-serverodbcherokuengineyard

RoR app deployed on Heroku and working with SQL Server database


Is it feasible to have a Ruby on Rails app, which is:

a) deployed on Heroku, and

b) working with a remote SQL Server database?

I take it that I'll need unixODBC installed on Heroku, but I cannot find a way to do so. Is this possible? Or, is there any other way (without ODBC?) to accomplish this?

Thank you very much for any guidance or tip.


Updated: Some info on the subject:

1) Heroku pre-installs both unixODBC and FreeTDS by default, so you already have them.

2) Also, it is possible to run shell commands via Heroku Console in backticks, e.g.:

  heroku console 
  `odbcinst`

(runs "odbcinst" command in Heroku shell and shows the result)

3) You do not have access to filesystem outside of your slice where the packages are installed. If you only need a driver path, Heroku support can provide it (/usr/lib/odbc/libtdsodbc.so in my case).

4) You cannot run sudo commands in Heroku shell.

At the moment, to connect to MS SQL Server you at least need to append ‘freetds.conf’ file. Even when using tinyTDS (there is an open ticket#2 in tinyTDS gitgub issue page). DSN-less connection instructions from "wiki.rubyonrails.org SLASH database-support SLASH ms-sql" didn’t work for me, I guess this connection requires some extra-configuration either.

‘freetds.conf’ cannot be modified without sudo. Therefore, I conclude that currently there is no way to make MS SQL and Heroku work together.

I’ve managed to set up this connection with EngineYard and activerecord-sqlserver-adapter.

I followed these instructions: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Platform-Installation---Ubuntu (there are only some filepath differences, e.g. ‘odbc.ini’ is located in ‘/etc/unicodbc’, not in ‘/etc’ - this is easy to work out).

I installed 'unixODBC' and 'freetds' packages using EY Unix Packages feature, and made all configurations manually through SSH. Sudo is available in EY (no password required). There is also Chef Recepes feature to automate those configurations (seems to be pretty easy, I'm going to try it tomorrow).

Hope this is helpful.


Solution

  • We're having a similar problem where we're needing to import old data from a SQL Server database into our new app. The data isn't a straight table import, but needs to undergo some processing and conversions. We've built an import layer for this which lives in a private gem, so as to not pollute the new app with the old data conversion issues. This approach is also designed to permit incremental updates, as we get closer to launch we'll keep syncing records up to the moment of switch-over.

    Heroku told us that it's not trivial to connect to SQLServer, in particular as they don't support FreeTDS. Their support staff recommended to run an instance with the import gem from a laptop in our office and configure it to connect to their database (which requires a dedicated DB, not the free shared one). This sounded like the most palatable approach to us.

    Secondly, regarding security that was mentioned by @Justice, we discussed configuring SSL for SQLServer with the hosting company and they pointed out the complexities of this. They recommended VPN as an easier solution. As we don't have office-side VPN hardware, the simplest and free solution proved to be an SSH tunnel.

    We've set up an SSH tunnel from the laptop to the SQLServer Windows box. That was straightforward. We had CopSSH installed on Windows (which comes with a Linux shell, by the way) and we were able to simply set up a tunnel, having the laptop talk to localhost for its SQLServer connection, i.e.:

    ssh -L 1433:localhost:1433 user@windows_server_name