Server Example 1

 

This example, during the Form_Load, walks the Servers collection adding each server to the list box. It then clears all the labels displaying server property information and the text box. When a server is selected from the list box, the click event sets the labels captions' to display server properties. Command1 is used to execute the Open method on the currently selected server using the string supplied in Text1. Command2 is used to run the Close method on the currently selected server. The application can be used to demonstrate various cases; different connection strings, Opens without a previous close, and the effect of open and close on the connected property and the last connected times.

 

Build this Server example as follows:

1. Create a new project and add a reference to the PISDK library.

2. Add the visual elements as shown in the picture. Make sure the numbered element names (label1, list1, ...;) match those shown.

3. Cut and paste the code below into the project.

 

Option Explicit

Private Sub Command1_Click()
On Error GoTo handler
  Dim srv As Server
  If List1.Text = "" Then
    MsgBox "Please select a server to open"
    Exit Sub
  End If
  Set srv = Servers(List1.Text)
  srv.Open Text1.Text
  ShowServerInfo srv
  Exit Sub
handler:
  MsgBox Err.Description
End Sub

Private Sub Command2_Click()
On Error GoTo handler
  Dim srv As Server
  If List1.Text = "" Then
    MsgBox "Please select a server to close"
    Exit Sub
  End If
  Set srv = Servers(List1.Text)
  srv.Close
  ShowServerInfo srv
  Exit Sub
handler:
  MsgBox Err.Description

End Sub

Private Sub Form_Load()
On Error GoTo handler
  Dim srv As Server
  For Each srv In Servers
    List1.AddItem srv.Name
  Next
  Text1.Text = ""
  ClearServerInfo
  Exit Sub
handler:
  MsgBox Err.Description
End Sub
Private Sub ClearServerInfo()
  Label10.Caption = ""
  Label11.Caption = ""
  Label12.Caption = ""
  Label13.Caption = ""
  Label17.Caption = ""
  Label18.Caption = ""
  Label19.Caption = ""
End Sub

Private Sub List1_Click()
On Error GoTo handler
  Dim srv As Server
  Set srv = Servers(List1.Text)
  ClearServerInfo
  ShowServerInfo srv
  Exit Sub
handler:
  MsgBox Err.Description
End Sub
Private Sub ShowServerInfo(srv As Server)
Label10.Caption = srv.Name
Label11.Caption = srv.Path
Label12.Caption = srv.Port
Label13.Caption = srv.ServerID
If srv.Connected Then
  Label17.Caption = "Connected"
Else
  Label17.Caption = "Disconnected"
End If
If srv.LastConnectedTime <> 0 Then
  Label18.Caption = srv.LastConnectedTime
Else
  Label18.Caption = "Never Connected"
End If
If srv.LastDisconnectedTime <> 0 Then
  Label19.Caption = srv.LastDisconnectedTime
Else
  Label19.Caption = "Never Disconnected"
End If
End Sub
Enabling Operational Intelligence