How to connect to SQL Server running on AWS?

北战南征 提交于 2019-12-08 14:19:33

问题


I am trying to connect to a SQL server running on AWS, located on a VM, the IP addresses of the VM and SQL server are different, can anyone please help me in creating a connection string?

The following connection string works inside the VM, but not outside where I want to connect:

sConnString = "Provider=SQLOLEDB;Persist Security Info=True;User ID=***;password=***;Initial Catalog=Dbname;Data Source=10.0.1.122;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=****;Use Encryption for Data=False;Tag with column collation when possible=False"

While running the same query outside the VM, I get an error saying

"Cannot connect to the server"

Is there something else I should be doing? Please help!

Rakshit


回答1:


Go to your EC2 control panel, security groups, and edit the inbound rules of the security group that is applied to your VM.

You should add your IP address into the inbound allowed IP4 addresses, por 1433.

Yeah, amazon EC2 only supports IP4 so if your internet provider is giving you only IP6 you're fried.

It may happen that the Windows Firewall is ON and configured to refuse external connections to port 1433 (which is unlikely since SQL Server installation does add the exception on the Windows Firewall for you) but just in case, check it out.

And yeah, as you probably connect from home, you IP4 address may change from time to time (depending on how stable your ISP is), so you'll have to allow your new IP in the Security groups panel over and over again, so... bad idea.

You could open the port 1433 to any IP but then you'll see in your Windows Event Logs a lot of "login failed for user sa" ... coming from Chinese or Russian IPs...

Anyways... just check the firewall, make your server as weak as you need it to and cross fingers.



来源:https://stackoverflow.com/questions/32991115/how-to-connect-to-sql-server-running-on-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!