Skip to content

EnumerateServersNetworkOrLocal - cMSSQLHandler

Enumerates Microsoft SQL Servers currently available on the local Windows machine OR on the network

Type: Function
Return Data Type: Integer

Parameters

Parameter Type Description
iNetworkLocal Integer 0 = network; 1 = local

Syntax

Function EnumerateServersNetworkOrLocal Integer iNetworkLocal Returns Integer

Call Example

Get EnumerateServersNetworkOrLocal iNetworkLocal to IntegerVariable

Description

This method enumerates Microsoft SQL Servers currently available on the local Windows machine OR on the network. The number of servers found is returned and the server names can be retrieved from the array (sMSSQLHandler's superclass is Array) with the value message.

Note that this function sometimes takes a long time to complete.

Sample

Object oServerNameComboForm is a ComboForm
    Set Size to 13 415
    Set Location to 5 60
    Set Label to "Server Name:"
    Set Label_Justification_Mode to JMode_Right
    Set Label_Col_Offset to 2

    Procedure OnChange
        Forward Send OnChange

        Send ToggleChangesPresent True
    End_Procedure

    Procedure ScanServers
        Handle hoSQLHandler
        Integer iNumServers iServer iNetworkLocal
        String sServer

        Forward Send Combo_Fill_List

        Get Create (RefClass (cMSSQLhandler)) to hoSQLHandler                
        If (hoSQLHandler <> 0) Begin
            Move 1 to iNetworkLocal // 1 = enumerate local servers
            Get EnumerateServersNetworkOrLocal of hoSQLHandler iNetworkLocal to iNumServers
            Decrement iNumServers
            For iServer from 0 to iNumServers
                Get Value of hoSQLHandler iServer to sServer
                Send Combo_Add_Item sServer
            Loop
            Send Destroy of hoSQLHandler
        End
    End_Procedure

    Procedure OnDropDown
        Send Combo_Delete_Data
        Send ScanServers
    End_Procedure
End_Object