简体   繁体   中英

make a c# connection to mysql running on linux virtual box from visual studio 2017 community

I'm using Visual Studio 2017 Community and I'm trying to make ac# connection to my MySQL database running on a virtual box ( linux Ubuntu ).

I added the MySQL.Data to the references and added 'using MySql.Data.MySqlClient;'.

Does anyone have a code example from their own project or something that has actually worked. None of the tutorial ones I've used so far have worked and each connection string looks slightly different from the others.

Here's what I have at this stage...

string myConnectionString = "datasource=192.168.1.102;port=3306;username=xxxxx;password=yyyyy;";
MySqlConnection myConnection = new MySqlConnection( myConnectionString );

try {
    myConnection.Open();
}
catch( Exception error ) {
    MessageBox.Show( error.Message );
}
finally {
    myConnection.Close();
}

First go to config file

sudo nano /etc/mysql/my.cnf

change

bind-address = 127.0.0.1

to

#bind-address = 127.0.0.1

also be sure that port is set to 3306

port=3306

then restart your server

sudo /etc/init.d/mysql restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM