简体   繁体   English

通过.net SDK连接到AWS RDS

[英]Connect to AWS RDS via .net SDK

I am sure this is out there but cannot seem to find it. 我确定这是存在的,但似乎找不到。 Currently I have an app in .net (WPF C#) that connects to a MS SQL like this; 目前,我在.net(WPF C#)中有一个可以像这样连接到MS SQL的应用程序;

string ConString = "Data Source=myDNS,1433;Initial Catalog=myDataBase;User Id=sa;Password=amazingpassword;";
string sqlCMD = "select * from myTable"
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(ConString))
{
   SqlCommand cmd = new SqlCommand(sqlCMD, con);
   SqlDataAdapter da = new SqlDataAdapter();
try
{
    con.Open();
    cmd = new SqlCommand(sqlCMD, con);
    da.SelectCommand = cmd;
    da.Fill(dt);
    con.Close();
}
catch (Exception x)
{
    /// <summary>
    /// Amazing error code
    /// </summary>
}
finally
{
    cmd.Dispose();
    con.Close();
}
}

Looking at moving the database hosting to Amazon RDS. 正在考虑将数据库托管移至Amazon RDS。 I want the database to be private so only connecting via the application would be possible. 我希望数据库是私有的,因此只能通过应用程序进行连接。 Is there an example of making a direct connection to the RDS database without exposing the database to the internet? 是否有一个直接连接到RDS数据库而不将数据库暴露在Internet上的示例? I also don't want to have to make VPN connection on the clients. 我也不想在客户端上建立VPN连接。 I am hoping that all that needs to be change is the actual connection and no changes to the sqlCMD would be needed. 我希望所有需要更改的是实际连接,而无需更改sqlCMD

Is there an example of making a direct connection to the RDS database without exposing the database to the internet? 是否有一个直接连接到RDS数据库而不将数据库暴露在Internet上的示例?

No, because it's not possible. 不可以,因为不可能。 An RDS database by its very nature is just a server sitting on the internet. 从本质上讲,RDS数据库只是位于互联网上的服务器。 Having said that, however, it is certainly possible for you to set things up in such a way that the database is protected and accessible securely from only your application. 话虽这么说,但是您当然可以通过以下方式设置事物:仅通过应用程序保护和安全访问数据库。

When you create your RDS instance you will want to create an associated security group for that instance. 创建RDS实例时,您将要为该实例创建一个关联的安全组。 An RDS security group contains one or more CIDR/IP definitions and/or names of existing EC2 security groups. RDS安全组包含一个或多个CIDR / IP定义和/或现有EC2安全组的名称。 Only hosts that fall within the IP address range(s) or EC2 security groups that you define will have access to the RDS instance. 只有属于您定义的IP地址范围或EC2安全组的主机才可以访问RDS实例。 Think of the RDS security group as a firewall for allowing/preventing access to the database. 将RDS安全组视为允许/阻止访问数据库的防火墙。 You can easily lock the RDS instance down so that only the server your running your app on has access to it. 您可以轻松锁定RDS实例,以便只有运行您的应用程序的服务器可以访问它。

I'm not familiar with .net, but the other thing you should also do is ensure you're connecting to the database via an encrypted (SSL) connection. 我对.net不熟悉,但是您还应该做的另一件事是确保您通过加密(SSL)连接连接到数据库。 The combination of using SSL and a security group that restricts access to the RDS instance should provide you with adequate security. 使用SSL和限制对RDS实例的访问的安全组的组合应该为您提供足够的安全性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM