Rails SQL Server failed connection

426 views Asked by At

it's my first time trying to get a rails app to connect to an external database.

I've installed active-record-sql-server-adapter and Tiny_Tds successfully and in the rails console I am able to connect to the database just fine.

when I try to connect from the actual application however (run migrations, pull data, etc.) I get this error:

Tiny_Tds::Error: Adaptive Server connection failed (localhost)

Please help

1

There are 1 answers

0
Lorin Thwaits On

In the error you received it mentions localhost, and that is the host you've got configured in database.yml as well. Should instead be your Azure server host name, something ending in "database.windows.net".

There is also a reference to a sqlite database file that can be removed -- pull out the line database: db/development.sqlite3. And instead of user: it should be username:. Putting all of that together, try something like this:

development:
  adapter: sqlserver
  encoding: utf8
  username:   (left out credentials intentionally here)
  password:   (left out credentials intentionally here)
  host: {xxx-xxx-xxx}-sqlserver.database.windows.net
  port: 1433
  azure: true
  database: <your database name>

More info about configuring an Azure connection is described in the docs from the rails gem The Brick.