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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay