In order to perform any database operations, it is necessary to log on 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.
// Logon to a session
CTSession ASession = new CTSession();
try
{
ASession.Logon("FAIRCOMS", "ADMIN", "ADMIN");
}
catch (CTException err)
{
Console.Write("Session logon failed with error {0}\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 = new CTSession();
CTBOOL createit = false;
// try to logon to a session
try
{
ASession.Logon("FAIRCOMS", "ADMIN", "ADMIN");
}
catch (CTException err)
{
if (err.GetErrorCode() == 12)
{
createit = true;
}
else
throw;
}
if (createit)
{
ASession.Create("FAIRCOMS", "ADMIN", "ADMIN");
try
{
ASession.Logon("FAIRCOMS", "ADMIN", "ADMIN");
}
catch (CTException err)
{
Console.Write("Logon failed with error {0}\n", err.GetErrorCode());
}
}
When operations with the session are no longer needed, it is necessary to log out from the session by invoking method CTSession.Logout(). Example:
CTSession ASession = new CTSession();
// logon to a session
try
{
ASession.Logon("FAIRCOMS", "ADMIN", "ADMIN");
// ... perform some other operations ..
ASession.Logout();
}
catch (CTException err)
{
Console.Write("Logon or Logout failed with error {0}\n", err.GetErrorCode());
}