Search code examples
ruby-on-railssql-servervirtualboxfreetdstiny-tds

How to connect my Rails App to SQL Server from Ubuntu Guest to Windows 8.1 Host?


I'm having issues setting up my rails app on a Windows 8.1 machine with Ubuntu through VirtualBox. I've done the following in attempts to try and connect my Ubuntu Guest Rails app to my Windows 8.1 SQL Server Express database.

  1. Setup a Bridged Connection on my Virtual Box network adapter
  2. I've installed my rails application and freetds on my ubuntu guest.
  3. In SQL Server Configuration Manager I enabled TCP/IP under SQL Server Network Configuration
  4. I also setup the correct login users for my database after creating it.

I am able to run my rails application on ubuntu with rails s and it runs fine. When I try to access it from my windows host or ubuntu guest it originally shows a GET until it finally errors and presents me with this message Unable to connect: Adaptive Server is unavailable or does not exist. I'm unsure what to try next. I was looking for a way to test the connection to the database outside of rails in just terminal to see if I could get a connection first but my attempts so far haven't produced anything. Below is my database.yml. The ip address I'm using is the ip address I get for windows host.

development:
  adapter: sqlserver
  dataserver: 192.168.1.114:1433
  host: 192.168.1.114
  port: 1433
  database: borneo
  username: marvin
  password: my_password
  pool: 5
  timeout: 5000

Solution

  • So I found a solution. After I had turned off the firewall I assumed that the firewall wouldn't be blocking anymore traffic; however, seems that I didn't turn it off properly I guess. The following method solved my problem.

    1. Go to Windows Firewall and Advanced Security
    2. Create an Inbound Rule for the Ubuntu Guest ip address for port 1433 using TCP.

    After I did that it worked.