Previous Topic

Next Topic

Creating a Session object

A valid session object is required to perform any session operation. The default parameter of the CTSession constructor is CTSESSION_CTDB.

// create a default CTSession object
CTSession ASession;
try
{
   // logon to session using default
   // server name, user name and password.
   CTSession.Logon();
}
catch (CTException &err)
{
   printf(“Session logon failed with error %d\n”, err.GetErrorCode);
}

If you create a dynamic CTSession object with the new operator, you are required to destroy the object with the delete operator.

// create a dynamic CTSession object
CTSession* pSession = new CTSession;

if (!pSession)
{
   printf(“CTSession allocation failed\n”);
}  
... other operations ..

// destroy the CTSession object
delete pSession;

When a session object is created, we can specify the session type. There are three different session types:

CTSESSION_CTREE

Allocate a new session for logon only. No session or database dictionary files will be used. No database functions can be used with this session mode. You must allocate table handles using the session handle.

CTSESSION_CTDB

Allocate a new session making full usage of c-treeDB session and database dictionaries. With this session mode, a Session dictionary file must exist to perform a session logon and you need to connect to a database before attempting to perform operation on tables.

CTSESSION_SQL

Allocate a new session for c-treeSQL processing.

// Create a session object
CTSession ASession(CTSESSION_CTDB);