0

I am working on a SQL Server database requirement.
SQL Server database is installed in a remote server system.
From a client I need to read the port configured on server.
Is it possible to do this from the client side, preferably using C++?

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • does [this](https://stackoverflow.com/questions/12297475/how-to-find-sql-server-running-port) help ? – Squirrel Aug 30 '22 at 06:01
  • 1
    This is why you use Instance Names in connection strings. Clients will use the [SQL Server Resolution Protocol](https://learn.microsoft.com/en-us/openspecs/windows_protocols/mc-sqlr/1ea6e25f-bff9-4364-ba21-5dc449a601b7) to communicate with the SQL Browser service via udp/1434 on the target server to resolve the instance name to the appropriate TCP port number, then the client connects to the instance via the resolved TCP port number. – AlwaysLearning Aug 30 '22 at 06:23
  • You could communicate directly with SQL Server Browser if you want. The protocol is defined here https://learn.microsoft.com/en-us/openspecs/windows_protocols/mc-sqlr/1ea6e25f-bff9-4364-ba21-5dc449a601b7 – Charlieface Aug 30 '22 at 12:07
  • @Charlieface Do you have any samples I could refer? I am new to this topic. – Amal Jesudas Aug 30 '22 at 16:14
  • Can some one confirm if below connection string and conditions are correct? Case1: Connection string with port number, NO NEED for SQL Server Browser >>>> CString connString("DRIVER={SQL Server};SERVER=\\InstanceName,1433;Network=DBMSSOCN;DATABASE=Name;UID=UserName;PWD=Password;"); Case2: Connection string without port number - SQL Server Browser MUST run >>>> CString connString("DRIVER={SQL Server};SERVER=\\InstanecName;Network=DBMSSOCN;DATABASE=Name;UID=UserName;PWD=Password;"); – Amal Jesudas Sep 01 '22 at 04:05

0 Answers0