Icon Connecting Sessions

As already discussed in the Architecture topic, the TEDBSession component represents a session in ElevateDB. The following information will show how to connect a session in an application.

Preparing a Local Session for Connection
If a TEDBSession component has its SessionType property set to stLocal, then it is considered a local session as opposed to a remote session. A local session must have values assigned to the LoginUser and LoginPassword properties if you do not wish to have ElevateDB display a login dialog when the session is connected.

The default Administrator user and password for an ElevateDB configuration is:

User: Administrator (case-insensitive)
Password: EDBDefault (case-sensitive)

Preparing a Remote Session for Connection
If a TEDBSession component has its SessionType property set to stRemote, then it is considered a remote session as opposed to a local session. In addition to the Login* properties detailed above that are required for a local or remote session, there are some additional properties for remote sessions that must be specified.

Connecting a remote session will cause ElevateDB to attempt a connection to the ElevateDB Server specified by the RemoteAddress or RemoteHost and RemotePort or RemoteService properties, and the RemoteConnectionTimeout property will indicate how long the remote session will wait for a successful connection attempt. In addition, the RemoteSignature property indicates the signature that the session's connection to the ElevateDB Server will be signed with, and the RemoteEncryption property indicates whether the session's connection to the ElevateDB Server will be encrypted using the RemoteEncryptionPassword property. You must set these properties properly before trying to connect the remote session or an exception will be raised.

Information Even if a session is not encrypted by setting the RemoteEncryption property to True, any login information is encrypted using the RemoteEncryptionPassword property during session login, so the RemoteEncryptionPassword must always match the corresponding server encryption password for session communciations or logins to the ElevateDB Server will fail. Please see the Configuring and Starting the Engine topic for more information on how to configure the server encryption passowrd used with session communications.

The RemoteAddress and RemoteHost properties are normally mutually exclusive. They can both be specified, but the RemoteHost property will take precedence. The host name used for the server can be specified via the "hosts" text file available from the operating system. In Windows, for example, it is located in the Windows\System32\Drivers\Etc directory. Adding an entry in this file for the ElevateDB Server will allow you to refer to the ElevateDB Server by host name instead of IP address. The following is an example of an entry for an ElevateDB Server running on a LAN:

192.168.0.1     ElevateDBServer

This is sometimes more convenient than remembering several IP addresses for different ElevateDB Servers. It also allows the IP address to change without having to modify your application.

The RemotePort and RemoteService properties are also normally mutually exclusive. They can both be specified, but the RemoteService property will take precedence. By default the port that ElevateDB Servers use is 12010. This port can be changed, however, so check with your administrator or person in charge of the ElevateDB Server configuration to verify that this is the port being used.

The service name used for the ElevateDB Server can be specified via the "services" text file available from the operating system. In Windows, for example, it's located in the \Windows\System32\Drivers\Etc directory. Adding an entry to this file for the ElevateDB Server's port will allow you to refer to the server's port by service name instead of port number. The following is an example of an entry for the server:

ElevateDBServer     12010/tcp

This is sometimes more convenient than remembering the port numbers for different ElevateDB Servers. It also allows the port number to change without having to modify your application.

The RemoteEncryption property can be set to either True or False and determines whether the session's connection to the server will be encrypted or not. If this property is set to True, the RemoteEncryptionPassword property is used to encrypt and decrypt all data transmitted to and from the ElevateDB Server. This property must match the same encryption password that the ElevateDB Server is using for communications with remote sessions (TEDBEngine ServerEncryptionPassword property) or else an exception will be raised when a request is attempted on the server.

If for any reason the remote session cannot connect to an ElevateDB Server, an exception will be raised. The error that is raised when a connection fails is 1100 (EDB_ERROR_CLIENTCONN). It's also possible for ElevateDB to be able to connect to the server, but the connection will be rejected due to the ElevateDB Server blocking the client workstation's IP address from accessing the server (1104 and defined as EDB_ERROR_ADDRBLOCK), or an encrypted connection being required by the ElevateDB Server (1105 and defined as EDB_ERROR_ENCRYPTREQ).

Connecting a Session
To connect a session you must set the TEDBSession Active property to True or call its Open method. For a local session (SessionType property is set to stLocal), the session will be opened immediately. As discussed above, for a remote session (SessionType property is set to stRemote), performing this operation will cause the session to attempt a connection to the ElevateDB Server specified by the RemoteAddress or RemoteHost and RemotePort or RemoteService properties. The connection attempt will wait the number of seconds specified by theRemoteConnectionTimeout property.

For both local and remote sessions, if the LoginUser and LoginPassword properties are specified and are valid, then neither the OnLogin event nor the interactive login dialog will be triggered. If these properties are not specified or are not valid, the OnLogin event will be triggered if there is an event handler assigned to it. If an event handler is not assigned to the OnLogin event, ElevateDB will display an interactive login dialog that will prompt for a user ID and password. All ElevateDB configurations require a user ID and password in order to connect and login. ElevateDB will allow for up to 3 login attempts before issuing an exception. The error that is raised when a connection fails due to invalid login attempts is 501 (EDB_ERROR_LOGIN).

Information Any version of ElevateDB for Delphi 6 or higher (including C++Builder 6 and higher) requires that you include the DBLogDlg unit in your uses clause in order to enable the display of a default login dialog. This is done to allow for ElevateDB to be included in applications without linking in the Forms unit, which can add a lot of unnecessary overhead and also cause unwanted references to user interface libraries. This is not required for Delphi 5 or C++Builder 5 since these versions always included the Forms unit.

The BeforeConnect event is useful for handling the setting of any properties for the session before the session is connected. This event is called right before the session is connected, so it is useful for situations where you need to change the session properties from values that were used at design-time to values that are valid for the environment in which the application is now running. The following is an example of using an BeforeConnect event handler to set the remote connection properties for a session:

procedure TMyForm.MySessionBeforeConnect(Sender: TObject);
var
   Registry: TRegistry;
begin
   Registry:=TRegistry.Create;
   try
      Registry.RootKey:=HKEY_LOCAL_MACHINE;
      if Registry.OpenKey('SOFTWARE/My Application',False) then
         begin
         if Registry.ReadBool('IsRemote') then
            begin
            with MySession do
               begin
               SessionType:=stRemote;
               RemoteAddress:=Registry.ReadString('RemoteAddress');
               RemotePort:=Registry.ReadString('RemotePort');
               end;
            end
         else
            MySession.SessionType:=stLocal;
         end
      else
         ShowMessage('Error reading connection information '+
                     'from the registry');
   finally
      Registry.Free;
   end;
end;

Information You should not call the session's Open method or toggle the Active property from within this event handler. Doing so can cause infinite recursion.

The AfterDisconnect event can be used for taking specific actions after a session has been disconnected. As is the case with the BeforeConnect event, the above warning regarding the Open method or Active property also applies for the AfterDisconnect event.

More Session Properties
A session can also be configured to control several global settings for all TEDBDatabase, TEDBTable, TEDBQuery, TEDBStoredProc, and TEDBScript components that link to the session via their SessionName properties. The properties that represent these global settings are detailed below:

PropertyDescription
ForceBufferFlushControls whether the session will automatically force the operating system to flush data to disk after every write operation completed by ElevateDB. Please see the Buffering and Caching topic for more information. The default value is False.
RecordLockProtocolControls whether the session will use a pessimistic or optimistic locking model when editing rows via navigational or SQL methods. Please see the Locking and Concurrency topic for more information. The default value is lpPessimistic.
RecordLockRetryCountControls the number of times that the engine will retry a row lock before raising an exception. This property is used in conjunction with the RecordLockWaitTime property. The default value is 15 retries.
RecordLockWaitTimeControls the amount of time, in milliseconds, that the engine will wait in-between row lock attempts. This property is used in conjuction with the RecordLockRetryCount property. The default value is 100 milliseconds.
RecordChangeDetectionControls whether the session will detect changes to a row during editing or deletion and issue an error if the row has changed since it was last cached. Please see the Change Detection topic for more information. The default value is False.
KeepConnectionsControls whether temporary TEDBDatabase components are kept connected even after they are no longer needed. This property has no obvious effect upon a local session, but can result in tremendous performance improvements for a remote session, therefore it defaults to True and should be left as such in most cases.
KeepTablesOpenControls whether the physical tables opened within the session are kept open even after they are no longer being used by the application. Setting this property to True can dramatically improve the performance of SQL statements and any other operations that involve constantly opening and closing the same tables over and over.
SQLStmtCacheSizeControls how many SQL statements can be cached in memory for each open database in the session. Caching SQL statements improves the performance of ElevateDB by avoiding very expensive preparation/un-preparation cycles. The default value is 0, which means that SQL statements will not be cached for the session. If a session needs to free any cached SQL statements, it can do so at any time by calling the TEDBSession FreeCachedSQLStmts method.
FuncProcCacheSizeControls how many functions/procedures can be cached in memory for each open database in the session. Caching functions/procedures improves the performance of ElevateDB by avoiding very expensive preparation/un-preparation cycles. The default value is 0, which means that functions/procedures will not be cached for the session. If a session needs to free any cached functions/procedures, it can do so at any time by calling the TEDBSession FreeCachedFuncProcs method.
ProgressTimeIntervalControls the amount of time, in milliseconds, that must elapse between progress updates before ElevateDB will generate a progress event. The default value is 1000 milliseconds, or 1 second.
ExcludeFromLicensedSessionsSpecifies whether the current session should be included in the session license count controlled by the TEDBEngine LicensedSessions property for local sessions, or by the ElevateDB Server for remote sessions. This is useful for situations where you have a utility session that you want to exclude from your own licensing restrictions, such as when a session is used in a thread for performance reasons.

Information This property does not cause the session to be excluded from the ElevateDB licensed session count and only affects the user-defined licensed session count.

Information You cannot modify any of the above properties unless the session is disconnected. Attempting to modify these properties while the session is connected will result in an exception being raised.
Image