I setup a Windows 7 on vm
on the same pc
, I have a form with the following code:
MySqlConnection connection = new MySqlConnection("SERVER = 127.0.0.1; DATABASE = my_test; UID = root; PASSWORD = 'XXXX';");
private void Form1_Load(object sender, EventArgs e)
{
MySqlCommand cmd = new MySqlCommand("SELECT * FROM info", connection);
connection.Open();
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
MessageBox.Show(reader[1].ToString());
}
}
reader.Close();
connection.Close();
}
on my pc
i successfully connect to the db, now i copy and paste my app to the vm and i get a jit
error i don't have any thing on the vm
(no appache
no mysql
nothing but net framework 4.0)
i did make my root user remote enabled like that:
GRANT ALL ON *.* to '%'@'%' WITH GRANT OPTION;
now i still stuck, so how to connect to the db with my ip
so the vm
can find it, and do i need to setup anything in the vm
?
Note: i can use another pc
if the problem in the VirtualBox
but i suspect that it has nothing to do with the VirtualBox
.
i am confused i made this form
and i move it to the vm and i asking simply: what to write in that textbox?
When you connect to
127.0.0.1
, you connect to the current system. Regardless of what system is running: main orvm
. You should configure network settings of theVirtualBox
so thatvm
can connect to your main system. In this case you'll connect fromvm
not to localhost but to IP-address that you set to mainOS
.Or you can setup
MySQL
to thevm
and move your database to thatMySQL
.EDIT
For testing connection to
MySQL
you can usetelnet
(http://windows.microsoft.com/en-us/windows/telnet-faq#1TC=windows-7). At first you should know theMySQL
port. You can get it fromMySQL
config or try ports from @Prageeth Roshane' answer. Then you should try to connect fromVirtualBox
toMySQL
to finded port. You can use or programm or telnet. If you'll have troubles with connections, try to check that the firewall in VM and in main OS is not blocked your programm (or telnet).P.S. If you can connect to
MySQL
from another PC, but cann't connect from VM, then trouble is in VM's network settings.Give a
PORT
that your mysql connection is using like 3308 or 3306