My code is still in development so when I run it it is on my local computer, but the database I am using is on an instance in EC2. I am having issues connecting to the data base. I am unsure of what the server name should be, i think. Does anyone know how to connect to a SQL server on EC2, or how to configure the connection string in the App.config file.
<connectionStrings>
<add name ="ConnectionString"
connectionString="server=000.000.000.000\EC2SQLEXPRESS;UID=UserID;PWD=xxxxxxxxxx;database=DBName"/>
In order to access the DB from EC2 you will need to use it’s public DNS name. You can find this on the Instance details page.
Bear in mind that if you Stop the instance and restart it that public DNS name will change. So you really should use an Elastic IP, associate it with your instance and have a normal public DNS name that points to the elastic IP. This way you won’t have to change your configuration info if you have to stop the instance.
Also, you will need to make sure the security group the database server is in has the desired port open. For SQL server the standard port is 1433.
FYI – It is generally considered bad practice for a database server to be directly accessible on the Internet. Instead you should have at least a web services layer in between you and the database that exposes ONLY the functionality you need.
However, if that isn’t feasible, then at bare minimum you should move SQL server to a different port and expose that through your security group settings. This doesn’t actually increase your security (it’s just obscuring the port) however most script attacks only target the standard SQL server ports like 1433. So, it would help reduce the number of attacks you’ll see.