My problem is trying to create a connection string in C# which connects to a SQL Server 2012 database remotely. I can successfully do this if the machine hosting the SQL Server does not require a port number to navigate to. Now that we have re-routed our ip’s a little, the ip to the machine hosting SQL Server is XXX.XXX.XXX.XXX:16500, where SQL Server is still listening on default port 1433.
I understand you can specify the port number that the SQL Server instance is using like so;
data source=XXX.XXX.XXX.XXX,1433;Network Library=DBMSSOCN;initial catalog=Order;User ID=test1;Password=test1;");
Our problem is, that our remote machine is not just an IP. It is an IP and a port.
XXX.XXX.XXX.XXX:16500 would manually navigate to the desired PC, ignoring the port number would take you to another machine. We are trying to accomplish something like this;
data source=XXX.XXX.XXX.XXX:16500,1433;Network Library=DBMSSOCN;initial catalog=Order;User ID=test1;Password=test1;");
I cannot find for the life of me how to do this. I want to set my data source to a remote IP:PORT, as well as set the port SQL Server will be listening on (I understand 1433 is the default, but in some cases we may have to change it, so it needs to be there for the future)
I have tried;
data source=XXX.XXX.XXX.XXX:16500,1433;Network Library=DBMSSOCN;initial catalog=Order;User ID=test1;Password=test1;");
ERROR:
A network-related or instance-specific error occured while
establishing a connection to the SQL Server…
data source=XXX.XXX.XXX.XXX:16500;Network Library=DBMSSOCN;initial catalog=Order;User ID=test1;Password=test1;");
ERROR:
A network-related or instance-specific error occured while
establishing a connection to the SQL Server…
data source=XXX.XXX.XXX.XXX,16500;Network Library=DBMSSOCN;initial catalog=Order;User ID=test1;Password=test1;");
ERROR:
A connection was successfully established with the server, but then
an error occurred durring the pre-login handshake. (Provider: TCP
Provider, error:0 – An existing connection was forcibly closed by the
remote host.)
Here it seems I am just connecting to the wrong server, trying to use port 16500 for SQL Server, which is not correct.
Can anyone please shine some light, is this possible?
This sounds like the IP address you have is actually a NAT device that forwards the traffic to another machine base on the port that was used to connect to it. If this is the case, you need to get your NAT administrator to create a public port on the NAT that will be forwarded to port 1433 on your SQL Server machine. Any port forwarding always only forwards to a single port, so what you were trying to do cannot work without that new forwarding rule being set up.