DEV Community

Cover image for SQL Server: Get database port
Sergio Peris
Sergio Peris

Posted on • Originally published at sertxu.dev

SQL Server: Get database port

The default port of SQL Server is 1433. But I can be different in some installations.

In order to get the port the SQL Server is listening, we can execute the following query:

xp_readerrorlog 0, 1, N'Server is listening on'
Enter fullscreen mode Exit fullscreen mode
2024-11-14 03:10:12.140 spid22s Server is listening on [ 'any' <ipv6> 57510].
2024-11-14 03:10:12.140 spid22s Server is listening on [ 'any' <ipv4> 57510].
2024-11-14 03:10:12.140 Server  Server is listening on [ ::1 <ipv6> 57511].
2024-11-14 03:10:12.140 Server  Server is listening on [ 127.0.0.1 <ipv4> 57511].
2024-11-14 03:10:12.150 spid22s Server is listening on [ ::1 <ipv6> 63454].
2024-11-14 03:10:12.150 spid22s Server is listening on [ 127.0.0.1 <ipv4> 63454].
Enter fullscreen mode Exit fullscreen mode

As we can see, the query is showing the server is listening to port 57510 from any IP address.

Top comments (0)