Sql-server – Connecting to server which located remotely throws timeout exception

connectivityremotesql server

Below are the steps which I follow while connecting manually:

  1. Connect to VPN
  2. RDP to the remote machine using my credentials
  3. Open SQL Server Management Studio
  4. Connect to Server > database engine, Server Name > "Name", Authentication > Windows Authentication
  5. Run query

And the connection string that I am using is:

ConnectionString = "Data Source =tcp:<IPAddress of RDP Machine>\<ServerName>;
Initial Catalog =<DBName>; User Id = <Username>; 
Password = <Password>; Trusted_Connection = True; 
Integrated Security = SSPI; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False"

Best Answer

In your manual procedure you state that you specify "name" in the server name, not an instance.

However in your connection string you specify

Data Source =tcp:<IPAddress of RDP Machine>\<ServerName>;

Which indicates <servername> should be used as an instance name.

You should probably remove \<servername> part of your connection string.

You should also verify the necessary ports are open on the firewall and make sure SQL Server is configured to allow remote connections as well as make sure tcp/ip is in the enabled protocols.

There is a decent MSDN blog post covering a lot of other steps you can take to troubleshoot your connectivity issues: Troubleshoot Connectivity/Login failures (18456 State x) with SQL Server