Reputation: 3677
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;
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. 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? I also don't want to have to make VPN connection on the clients. I am hoping that all that needs to be change is the actual connection and no changes to the sqlCMD
would be needed.
Upvotes: 1
Views: 4263
Reputation: 20759
Is there an example of making a direct connection to the RDS database without exposing the database to the internet?
No, because it's not possible. An RDS database by its very nature is just a server sitting on the internet. 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. An RDS security group contains one or more CIDR/IP definitions and/or names of existing EC2 security groups. Only hosts that fall within the IP address range(s) or EC2 security groups that you define will have access to the RDS instance. Think of the RDS security group as a firewall for allowing/preventing access to the database. You can easily lock the RDS instance down so that only the server your running your app on has access to it.
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. The combination of using SSL and a security group that restricts access to the RDS instance should provide you with adequate security.
Upvotes: 2