Can't connect from C# using MySqlConnection
Posted by: Cristian Mitta Lindo
Date: November 06, 2013 10:22AM

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

Options: ReplyQuote


Subject
Written By
Posted
Can't connect from C# using MySqlConnection
November 06, 2013 10:22AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.