A web application may require a means by which it can track active session usage within the database server. Session data can be found using the NEXT_CONNECTION function call to iterate through the active database connections and checking for session related properties such as SessionID. The following SQL code demonstrates this approach:
CREATE VARIABLE conn_id LONG VARCHAR; CREATE VARIABLE the_sessionID LONG VARCHAR; SELECT NEXT_CONNECTION( NULL, NULL ) INTO conn_id; conn_loop: LOOP IF conn_id IS NULL THEN LEAVE conn_loop; END IF; SELECT CONNECTION_PROPERTY( 'SessionID', conn_id ) INTO the_sessionID; IF the_sessionID != '' THEN PRINT 'conn_id = %1!, SessionID = %2!', conn_id, the_sessionID; ELSE PRINT 'conn_id = %1!', conn_id; END IF; SELECT NEXT_CONNECTION( conn_id, NULL ) INTO conn_id; END LOOP conn_loop; PRINT '\n';
If you examine the database server messages window, you might see output similar to the following.
conn_id = 30 conn_id = 29, SessionID = session_63315442223323 conn_id = 28, SessionID = session_63315442220088 conn_id = 25, SessionID = session_63315441867629
Explicitly dropping a connection that belongs to a session causes the connection to be closed and the session to be deleted. If the connection being dropped is currently active in servicing an HTTP request, the request is marked for deletion and sent a cancel signal to terminate the request. When the request terminates, the session is deleted and the connection closed. Deleting the session causes any pending requests on that session's queue to be requeued as discussed in Deleting or changing the session ID. In the event the connection is currently inactive, the session is marked for deletion and requeued to the beginning of the session timeout queue. The session and the connection are deleted in the next timeout cycle (normally within 5 seconds). Any session marked for deletion cannot be used by a new HTTP request.
When stopping a database unconditionally, each database connection is dropped, causing all sessions under that database context (see the description of session key in Creating an HTTP session) to be deleted. This is guaranteed since one valid database connection must exist for one session context and a database connection can only be associated with one session at a time. Both the session and database connection must be within the same database context.
|Send feedback about this page via email or DocCommentXchange||Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0|