简体   繁体   English

Rails:如何从virtualbox guest虚拟机(ubuntu)访问主机(windows)上的数据库?

[英]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. 在下面,我将概述为使其正常工作而要做的一些事情,因为该过程与流程略有不同。

  1. 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重新启动服务器(连接后右键单击连接,然后选择“重新启动”),我就可以连接!

  2. 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  
  1. Finally, remember to give the user the right permissions. 最后,请记住要授予用户正确的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将我的Rails应用程序从Ubuntu Guest到Windows 8.1主机连接到SQL Server? - How to connect my Rails App to SQL Server from Ubuntu Guest to Windows 8.1 Host? 有什么方法可以从Windows 7访问Ubuntu VM的Rails应用程序? - Is there a way I can access my Rails Application of my Ubuntu VM from my Windows 7? 使用 VirtualBox 从来宾访问主机上的站点? 主机和来宾是 linux - Use VirtualBox to access site on host from guest? the host and guest is linux 如何在Windows 7上使用Vagrant访问我的Virtualbox - How do I access my Virtualbox using Vagrant on Windows 7 如何托管我的Ruby on Rails应用程序-没有托管提供商提供SQLite3数据库 - How can I host my Ruby on Rails application - no hosting providers offer SQLite3 database 如何从Rails中的自定义模块访问参数? - How can I access params from my custom module in Rails? 如何从数据库中获取用户ID-rails - How can I get the User ID from my database — rails 如何从Rails中的外部数据库同步数据? - How can I sync my data from an external database in Rails? VirtualBox:无头VM:从主机访问Web应用程序。 - VirtualBox: Headless VM: Access web application from host machine. 如何让Heroku在Ubuntu 10.10上工作(在Windows机器上使用VirtualBox)? - How do I get Heroku to work on Ubuntu 10.10 (using VirtualBox on Windows machine)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM