I'm trying to setup my rails project (guest: ubuntu) so it can access the sql server database on my host os windows. I'm using virtual box but, I'm unsure what my "host" should be set to in my database.yml
file. How can I find out which IP address and port to set it to? When I had the project on my windows operating system I was able to configure it to host:localhost
I had to find the listed default gateway. So I opened up terminal on Ubuntu and used the following command: netstat -rn
. That gave the following result...
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
From there I noticed the Default Gateway was 10.0.2.2
. I setup my database.yml as follows:
development:
adapter: sqlserver
host: 10.0.2.2
database: Development
username: username12345
password: password12345
pool: 5
timeout: 5000
And the connection worked! Hope this helps someone else in a similar situation.
EDIT:
So I ran into a very similar problem when attempting to do this same setup on a computer where the host was running SQLExpress. Below I'll outline some of the things that I did to get it working since it was a little different of a process.
You have to enable the TCP/IP connection (in a couple of places) and specify the port being used.
Go To: Start > All Programs > Microsoft SQL SERVER 2008 > Configuration Tools > SQL Server Configuration Manager
. Then expand SQL SERVER NETWORK CONFIGURATION
and enable all the protocols in the right pane. Now, right click and select Properties
from TCP/IP
from the right-pane. Under the Protocol
tab make sure "Enabled" is set to "Yes". Under IP Address
tab I made sure all the IPs were set to "Yes" for Enabled
and Active
. Finally, I added my port 1433
to IP8 which was my 127.0.0.1
IP and also to the IP All
at the very bottom of the scroll box. Once that was applied and I restarted the server via SQL Server Management Studio (right click the connection once connected and select "restart") I was able to connect!
I also used a slightly different database.yml
file.
development:
adapter: sqlserver
dataserver: 10.0.2.2:1433
host: 10.0.2.2
port: 1433
database: Development
username: username12345
password: password12345
pool: 5
timeout: 5000