|
Mastering PowerBuilder Stopping Connections RemotelyDeclare of_Disconnect function at w_pms_server as shown below.
// Function: of_Disconnect
// Access: Public —We need to allow the menu to
// fire this function, so, it should be public.
// Returns: None
// Arguments: as_user, String, by Value
ConnectionInfo lci_ConInfo[]
nuo_Connection lcn_Connection
int li_RowNo, li_rc
long ll_Rows, ll_Row
String ls_User
lcn_Connection = CREATE nuo_Connection
lcn_Connection.Application = gtrp_transport.Application
lcn_Connection.Driver = gtrp_transport.Driver
lcn_Connection.Location = gtrp_transport.Location
lcn_Connection.UserId = "DBA"
lcn_Connection.Password = "SQL"
lcn_Connection.ConnectToServer()
IF lcn_Connection.ErrCode <> 0 THEN
MessageBox("Error", string(lcn_Connection.ErrCode)&
+ ": " + lcn_Connection.ErrText, &
StopSign!,OK!,1)
lcn_Connection.DisconnectServer()
DESTROY lcn_Connection
RETURN
END IF
IF Upper(as_user) = "ALL" THEN
ll_Rows = lcn_Connection.GetServerInfo( lci_ConInfo )
// Your connection is listed always top, so, don't
// disconnect yourself first. Disconnect others.
// Once done, you are disconnecting yourself at the
// end anyway.
FOR li_RowNo = 2 TO ll_Rows
li_rc = lcn_Connection.RemoteStopConnection(&
lci_ConInfo[li_RowNo].ClientId)
NEXT
dw_users.Reset()
ElseIf Upper(as_user) = 'CURRENT' Then
ll_Row = dw_users.GetRow()
If ll_Row > 0 Then
ls_User = dw_users.getItemString(ll_row,'clientid')
li_rc = lcn_Connection.RemoteStopConnection(ls_user)
if li_rc = 0 Then dw_users.deleteRow( ll_Row )
End If
ELSE
li_rc = lcn_Connection.RemoteStopConnection(as_user)
END IF
lcn_Connection.DisconnectServer()
DESTROY lcn_Connection |
We the user requests to stop all connections, we are calling GetServerInfo() and stopping each connection from connection #2 by calling RemoteStopConnection(). The reason we are starting from connection #2 instead of #1 is that, even though this function is being called from the server console window, still you need to connect to the server by opening another connection. GetServerInfo() always returns the current connection information as the first record. So, first we need to stop all other connections and disconnect from the server meaning all connections are dropped.
If the user requests to drop a specific connection, then we are just stopping that specific connection.
|