Session logon and logoutIn 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
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:
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) {
} } When operations with the session are no longer needed, it is necessary to logout from the session by invoking method CTSession::Logout(). Example
// 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()); } |
|||