[英]Rails: How can I access my database on my host machine (windows) from a virtualbox guest (ubuntu)?
I'm trying to setup my rails project (guest: ubuntu) so it can access the sql server database on my host os windows. 我正在尝试设置我的rails项目(来宾:ubuntu),以便它可以访问主机OS窗口上的sql server数据库。 I'm using virtual box but, I'm unsure what my "host" should be set to in my
database.yml
file. 我正在使用虚拟盒,但是不确定在我的
database.yml
文件中应将“主机”设置为什么。 How can I find out which IP address and port to set it to? 如何找到将其设置为哪个IP地址和端口? When I had the project on my windows operating system I was able to configure it to
host:localhost
当我在Windows操作系统上拥有该项目时,我能够将其配置为
host:localhost
I had to find the listed default gateway. 我必须找到列出的默认网关。 So I opened up terminal on Ubuntu and used the following command:
netstat -rn
. 因此,我在Ubuntu上打开了终端,并使用了以下命令:
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
. 从那里我注意到默认网关是
10.0.2.2
。 I setup my database.yml as follows: 我将我的database.yml设置如下:
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. 因此,当尝试在主机运行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. 您必须启用TCP / IP连接(在几个地方)并指定使用的端口。
Go To: Start > All Programs > Microsoft SQL SERVER 2008 > Configuration Tools > SQL Server Configuration Manager
. 转到:
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. 然后展开“
SQL SERVER NETWORK CONFIGURATION
并在右窗格中启用所有协议。 Now, right click and select Properties
from TCP/IP
from the right-pane. 现在,右键单击并从右窗格中选择“
TCP/IP
Properties
。 Under the Protocol
tab make sure "Enabled" is set to "Yes". 在“
Protocol
选项卡下,确保将“启用”设置为“是”。 Under IP Address
tab I made sure all the IPs were set to "Yes" for Enabled
and Active
. 在“
IP Address
选项卡下,我确保将“ Enabled
和“ Active
”的所有IP都设置为“是”。 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. 最后,我将端口
1433
添加到IP8(这是我的127.0.0.1
IP),也添加到了滚动框最底部的IP All
。 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! 一旦应用后,我就可以通过SQL Server Management Studio重新启动服务器(连接后右键单击连接,然后选择“重新启动”),我就可以连接!
I also used a slightly different database.yml
file. 我还使用了稍微不同的
database.yml
文件。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.