Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

Can't connect from C# using MySqlConnection (2 replies)

$
0
0
Hi everyone,
I am trying to write a program in C# that elaborates some data and then puts it in a remote database.
I have been trying all sort of different things and finally managed to make the following code work.


string connStr = "server=localhost;user=username;database=dbname;port=3306;password=passwd;";

MySqlConnection conn = new MySqlConnection(connStr);
bool connected = false;
try
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();
connected = true;
// Perform database operations
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (connected)
MessageBox.Show("WOWOWOWOWO it's working!!!!!!!!!");
else
MessageBox.Show(":'(");
conn.Close();

As you probably noticed I said that I want to connect to a remote DB and in the connection string I've put localhost.
This is my problem, if I connect to a local database everything works fine, when I try to connect to the remote one it never works.
I've thought about all the server-side problems i could think of:
- remote access not allowed (but I have other software that use that DB and it works fine with it)
- only certain IPs could access the DB (but again other software can access from any IP)

So I'm asking if any of you could give me a hand and point out what I've missed/did wrong

Thanks for your time,
Cristian

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>