Just Code‎ > ‎

C# - Find SQL server instance port number

posted Aug 27, 2013, 6:41 AM by Peter Henell   [ updated Aug 27, 2013, 6:41 AM ]

using System;

namespace LookForPortNumberOfSqlServer
{
    class Program
    {
        static void Main(string[] args)
        {
            string instanceName = "SQL2012";
            string regSearch = @"HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\" + instanceName + @"\MSSQLServer\SuperSocketNetLib\Tcp\";
            Object found = Microsoft.Win32.Registry.GetValue(regSearch, "tcpPort", "not found");
            Console.WriteLine(regSearch);
            Console.WriteLine(found);
        }
    }
}
Comments