KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Setting SQL Server Port Value by Code
PRODUCT: 4D | VERSION: 14 R4 | PLATFORM: Mac & Win
Published On: June 4, 2015

Starting with 4D v14 R3, the SQL Server Port ID value can be set with SET DATABASE PARAMETER by passing 88 as the selector or using the constant SQL Server Port ID. The current Port value can be obtained using the same selector with the Get database parameter.

With these commands the following method can be used to modfiy the port value of the SQL Server and restart the server. The method will return a 1 if the method is successful or a 0 if not:

C_LONGINT($1;$newPort_l)
C_LONGINT($0)

$0=0
If(Count Parameters=1)
  $newPort_l:=$1

  STOP SQL SERVER

  If(Get database parameter(SQL Server Port ID)#$newPort_l)
    SET DATABASE PARAMETER(SQL Server Port ID;$newPort_l)
    START SQL SERVER
    $0=OK
  End if
End if


Note that this value will also be applied to the database settings and will be kept after restarting the database.