Alex
Alex

Reputation: 553

Connect successfully to SQL Server despite using different port

We have a client that connects to SQL Server using Windows authentication. They connect using the server name and port number (not 1433).

All our software installations thus far connect to SQL Server using SQL Server authentication, connecting with server name, user name and password.

I am trying to setup a test on my computer to see whether I can connect with our software using the setup used by this client, in other words Windows authentication, with server name and port number. The port number is what is new to me here.

The problem I am having is that I can connect successfully regardless of the port number of the SQL Server installation, and what I pass in as a port number from our software. So I am obviously doing something wrong, or misunderstanding how this works. Any help would be appreciated.

My first step was to open SQL Server Configuration Manager > Network configuration > Protocols for my instance > TCP/IP > Properties. I then opened the IP addresses tab, and changed the TCP port to 41000 (I sucked this number out my thumb) on all the IP1 - IPAll sections. The TCP dynamic port setting is blank for all these. I applied, saved and restarted the server.

In the DbExpress TSQLConnection connection parameters, I pass in:

TSQL1connection.Params.Add('OSAuthentication=True');
TSQL1connection.Params.Add('HostName='+SQL_server_name); 
TSQL1connection.Params.Add('Port=123');

It doesn't seem to matter what I put in the port number, or whether I leave the port setting out altogether; I always manage to successfully connect.

I want to have it successfully connect only to the port number specified.

I am using SQL Server 2014 and Delphi XE8.

Upvotes: 0

Views: 367

Answers (1)

Dsm
Dsm

Reputation: 6013

I don't know TSQLConnection, but I do know a bit about TCP/IP, and I suspect that the issue here is just a misunderstanding about ports. There are always two ports involved in a connection, in this case the server port and the client port. They are not the same. The 41000 is the server port in this case, and I assume that 123 is the client port. That is perfectly fine to establish a connection, and that is why it doesn't matter what port number you put in.

In terms of solving your problem, you need to reject the connection at the SQL Server end. The server will know the client port after the connection, but whether you can access that data and force a rejection, I am afraid I do not know.

Upvotes: 1

Related Questions