Reputation: 392
I have a .net core program running on ubuntu, and I need to add a connection to the database running on the same machine.
I created a test program on my windows machine which connected to and interacted with the database and tables I want perfectly (via a putty tunnel), but used MySql.Data.MySqlClient
, which it would seems is windows specific. I copied the connection.cs
code up to the ubuntu server (changed the namespace, referenced it it the main program etc.). When i try to build, it can't find MySql.Data.MySqlClient
(type or namespace error on mysql).
Is getting it working a matter of a) loading MySql.Data.MySqlClient
into the ubuntu machine, b) using a different package (if so does anyone know what) or c) doing it a totally different way.
I have tried looking at tutorials/ other SO posts to see their code but none of them are about connecting to a normal db hosted on the same machine.
Upvotes: 0
Views: 136
Reputation: 3886
Shamelessly copypasta'd from https://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting-connection-string.html
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString = "server=127.0.0.1;uid=root;" +
"pwd=12345;database=test";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}
You do need to install MySQLClient on your ubuntu machine if it's not there already. Just select it in your package manager.
Also, if this doesn't work, verify that mysql is actually listening on a TCP port. It's possible that you're attempting a TCP connection but its actually listening on a socket.
https://dev.mysql.com/doc/refman/8.0/en/can-not-connect-to-server.html
Upvotes: 2