Just copy and paste the T-SQL code and execute to get the port number used by SQL server. This is how it works.
- Determine which version of SQL server you are running
- Look at the specific location in the registery
- Display the port number
I have tested this script on the following versions
- SQL 2000 - 32 bit
- SQL 2005 - 32 and 64 bit
- SQL 2008 - 32 and 64 bit
- SQL 2008R2 - 32 and 64 bit
It is quick, simple and could be executed on develoopment and production servers as there are not changes being made to SQL server and/or the Window's registery.
You will need to ensure you have rights to read the register in order for the script to execute properly and must be executed on each instance (this version) to get the port number)