Controlling and Monitoring the Server Connection
Panorama normally connects to the server automatically when a database is opened, and disconnects when it is closed. However it is possible to override this default behavior and connect and disconnect on command. This can either be done manually from the File menu (see Temporarily Disconnecting a Shared Database from the Server) or in a program using the connecttoserver and dropserver statements, as described below.

### ConnectToServer Statement

The connecttoserver statement tells Panorama to connect the current database with the server (of course this only works for shared databases, and only if the database is not already currently connected). The statement has no parameters. For example suppose the network was not working when a shared database was opened — perhaps the Ethernet cable was not plugged in. After plugging in the cable you can use a procedure with the connecttoserver statement to establish the connection (otherwise you would have to close and re-open the database to get the connection working).

### DropServer Statement

The dropserver statement tells Panorama to disconnect the current shared database from the server (of course this only works for shared databases, and only if the database is currently connected). For example you might use this statement if you are planning on unplugging your network connection but want to con- tinue working with the database offline (see Temporarily Disconnecting a Shared Database from the Server). This statement has no parameters.

### The info(“serverconnection”) Function

The info(“serverconnection”) function returns true if the current database connected to the server when it opened, false if it did not. The example below displays an error message if the database is not currently connected.

    if (not info("serverconnection"))
        message "Database is not currently connected."
        return
    endif

In a real procedure the code would probably perform some function after the `endif` statement. If the server connection were lost for some reason after the database was opened, this function would still return true.

### The sharedusers( Function

The sharedusers( function returns a list of users that are currently sharing a database. The function has one parameter, the name of the database. The specified database must currently be connected to the server on this computer. If the database is not connected, or is not a sharable database, the result will be `""`. If the database name is `""` then the current database will be used.

If this is a connected database the result will be a carriage return separated array, with each line containing the session id, user name, and user’s computer’s name separated by tabs. Here’s a typical example of the output from this function.

    12   Rudy Red       Conference Room Computer
    15   Marie Ellis    Marie’s Computer
    29   Mark Watson    Mark’s Computer

This example procedure checks to see if the user Rudy Red is using the same shared database we are right now.

    if sharedusers("") contains tab()+"Rudy Red"+tab()
        message "Rudy is online right now!"
    endif

The sharedusers( function can also be used to list all users on the server, not just the ones using a specified database. To do this set the database name to `"*"` (the current database must be a shared database for this to work).

### The servername( Function

The servername function returns the name of the server associated with a shared database. The function has one parameter, the name of the database. If the database name is `""` the server name for the current database will be returned.

### The serverdatabasename( Function

The name of a database on the server is not necessarily the same as the name of the same database on the client computer. (In fact, you can actually have more than one copy of a single database on a client computer with different names even though each connects to the same database on the server, though we can’t think of any reason why you’d want to do that.) Procedures usually don’t need to know the name of the database on the server, but if they do they can use the serverdatabasename( function to find out what it is. This function has one parameter, the name of the database. If the database name is `""` the server name for the current database will be returned.

See Also

- Bulk Data Transformations on Shared Databases -- using formulafill, propagate, etc. in a shared environment.
- Looking up Data Directly from the Server -- local in-memory vs. server lookups.
- Record Locking in Procedure Code -- implicit and explicit management of record locking.
- Server Variables (Shared Variables) -- sharing variable values across multiple users.
- Synchronizing in Procedure Code -- customizing the data synchronization process.

History

Version | Status | Notes
10.2 | New | New in this version.