Previous Topic

Next Topic

Session logon and logout

In order to perform any database operations, it is necessary to logon to a c-tree session. A session is terminated with a session logout.

To log on to a session, a CTSession object must be instantiated and then CTSession::Logon() method should be called to perform the session logon.

Example


// Logon to a session
CTSession ASession;
try
{
   ASession.Logon(“FAIRCOMS”, “ADMIN”, “ADMIN”);
}
catch (CTException &err)
{
   printf(“Session logon failed with error %d\n”, err.GetErrorCode());
}

Note: A useful sequence in code is to try to log on to the session, and if it fails with error FNOP_ERR (12), create the session dictionary and then log on again.

Example:


CTSession ASession;
CTBOOL createit = NO;
// try to logon to a session
try
{
   ASession.Logon(“FAIRCOMS”, “ADMIN”, “ADMIN”);
}
catch (CTException &err)
{
   if (err.GetErrorCode() == FNOP_ERR)
   {
      createit = YES;
   }
   else
      throw;
}
if (createit)
{
   ASession.Create(“FAIRCOMS”, “ADMIN”, “ADMIN”);
   try
   {
      ASession.Logon(“FAIRCOMS”, “ADMIN”, “ADMIN”);
   }
   catch (CTException &err)
   {
printf(“Logon failed with error %d\n”, err.GetErrorCode());
   }
}

When operations with the session are no longer needed, it is necessary to logout from the session by invoking method CTSession::Logout().

Example


CTSession ASession;
// logon to a session
try
{
  ASession.Logon(“FAIRCOMS”, “ADMIN”, “ADMIN”);
  // ... perform some other operations ..
  ASession.Logout();
}
catch (CTException &err)
{
  printf(“Logon or Logout failed with error %d\n”, err.GetErrorCode());
}