13

I am currently using Amazon EC2 (AMI linux) + MySQL, and now I am working on C# stuff.

I wrote code like this:

        MySqlConnection DBConn = new MySqlConnection();
        DBConn.ConnectionString = "Server=ec2-**.compute-1.amazonaws.com;Database=****;uid=root;password=****;port=3306;charset=utf8";

        try
        {
            DBConn.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show("connecting fail");
        }

But for some reason, when I run this, it generates a 'connecting fail' error.

I googled and figured out that I need to set "grant all privileges *.* to root@'localhost' "

So, I did that!

But it still doesn't work. I think I followed all of the steps though.

  • I am working on Visual studio 2008 & Windows7 at the moment.

  • I Checked the error and it seems like it's a timeout error. I think it's a firewall thing but don't know what I should do. I set my security group so the TCP ports are opened to all (incl. Mysql). It's still not working. Isn't that the way to solve this problem?;( However, the thing that I am curious about is that I could access to the database using MySQL workbench before I set the security group.

Sorry that I am totally new to EC2.

Bron Davies
  • 5,930
  • 3
  • 30
  • 41
user1313310
  • 131
  • 1
  • 7

2 Answers2

0

1) You should open MySQL port on your server via aws console. you can do it by clicking by go to DB Security Groups on RDS section, and just put CIDR:0.0.0.0/0 to test you are connected and status is authorized. Then you can rearrange rules to specify which ip can connect.
2) You should use MySQL connector to connect MySQL from C#.
Mysql Connector Link
3) Your connection string should be like :

Server=yourdburl;
Database=yourdb; 
Uid=yourdbuser; 
Pwd=yourdbuserpassword;
charSet=utf8;

3rd one seems right, you should check 1st and 2nd cases.

gandil
  • 5,398
  • 5
  • 24
  • 46
0

You should turn on VPC Flow Logs on that ENI to see if the connection is getting accepted on that interface, or rejected. High chance that your security groups are no correct, as gandil mentioned.

rajat banerjee
  • 1,256
  • 2
  • 12
  • 21