English 中文(简体)
与EC2连结的C # # 问题
原标题:Issues about C# connecting to EC2

我目前在使用亚马逊EC2(AMI Linux)+ MySQL,

我写了这样的代码:

        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");
        }

但出于某种原因,当我运行它的时候, 它会产生连接的故障错误。

我上网搜索,发现我需要设置“给予所有特权 *. * 至root@ localhost”

所以我就这么做了! So, I did that!

但它仍然不起作用。我想我跟踪了所有的步骤。

  • 我目前在2008 & amp; Windows7 视觉工作室工作。

  • 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.

对不起,我是全新的EC2。

问题回答

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;

第三位看来是对的,你应该检查第一和第二案例

您应该打开< a href=> https://aws. amazon.com/blogs/aws/vpc-flow-logs-logs-and-view-network-traffic- flows/" rel="nol="nofollow norefererr">VPC Flow Lologs 来查看该接口是否接受或拒绝连接。 Gandil 提到, 您的安全集团极有可能不正确 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签