Creating an HTTP session

A session is created within a web application using the HTTP option SessionID by calling the sa_set_http_option system procedure. A session ID can be any non-null string. Internally, a session key composed of the session ID and database name is generated so that the session key is unique across databases in the event that multiple databases are loaded. The entire session key is limited to 128 characters in length. In this example, a unique session ID is generated and passed to sa_set_http_option.

DECLARE session_id VARCHAR(64);
DECLARE tm TIMESTAMP;
SET tm=now(*);
SET session_id = 'session_' || 
    CONVERT( VARCHAR, SECONDS(tm)*1000+DATEPART(millisecond,tm));
CALL sa_set_http_option('SessionID', session_id);

A web application can obtain the session ID through the SessionID connection property. This property is an empty string if no session ID is defined for the connection (that is, the connection is sessionless).

DECLARE session_id VARCHAR(64);
SELECT CONNECTION_PROPERTY( 'SessionID' ) INTO session_id;

Once the session is created with the sa_set_http_option procedure, a localhost client can access the session with the specified session ID (for example, session_63315422814117) running within the database dbname running the service session_service with the following URL.

http://localhost/dbname/session_service?sessionid=session_63315422814117

If only one database is connected, then the database name can be omitted.

http://localhost/session_service?sessionid=session_63315422814117