none
Why MAPILogonEx keeps return the same session interface pointer

    Question

  • When my mapi application lost connection to exchange server, I need to recreate session.

    I create the session by calling MAPILogonEx() with these flags

        MAPI_NEW_SESSION | MAPI_UNICODE | MAPI_EXPLICIT_PROFILE | MAPI_EXTENDED |

     MAPI_NT_SERVICE;

    I do

    _session->Logoff(0,0,0);

    _session->Release();

    The problem I have is when I call MAPILogonEx() again, I keep getting the same

    LPMAPISESSION back.

    How do I get around it and force it to create a new session?

    Thanks,

    Bin



    Bin

    Friday, May 02, 2014 1:13 AM

All replies

  • Can you successfully connect with that new-old session?

    What version of Outlook are you using? Recent versions of Outlook reconnect automatically.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, May 02, 2014 2:00 AM
  • Hello Bin,

    I have noticed the MAPI_NT_SERVICE flag. Do you develop a windows service?

    Did you try to call the MAPIInitialize and MAPIUninitialize methods?

    Friday, May 02, 2014 11:50 AM
  • Yes, the application runs as windows services.  So I can call the MAPIInitialize and MAPIUninitialize methods multiple times?

    There could be multiple profiles.  I don't want to close all of them.  Is there another way to force creating a new session?  Isn't MAPI_NEW_SESSION supposed to do it?

     

    Thanks,


    Bin


    • Edited by bin lin Friday, May 02, 2014 1:18 PM
    Friday, May 02, 2014 1:09 PM
  • My  application runs as windows service.  When there is error with exchange connection, it had problem open message store.  So logoff and logon again, it seems that if it gets the same session handle pointer pack, it would keep getting the same error of not being able to open the message store.  In my testing setup, it returns different session pointer, therefore, it could reconnect and reopen message without problem.

    Bin

    Friday, May 02, 2014 1:13 PM
  • Is there another method other than calling MAPIUninitialize and MAPIInitialize?

    Bin

    Wednesday, May 07, 2014 1:20 PM
  • Why do you care whether a new pointer is returned? What is the exact problem that you are trying to solve? Doesn't the session returned work correctly?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, May 07, 2014 1:28 PM
  • There are no other methods for initializing the MAPI subsystem. Do you call the MAPIInitialize method only time?
    Wednesday, May 07, 2014 1:54 PM
  • It keeps getting the same error open message store.

    (80040115) Microsoft Exchange is not available.  Either there are network problems or the Exchange server is down for maintenance.

    _session->Logoff(0,0,0);

    _session->Release();

    MAPILogonEx()

    does not work.  I have to restart the application( a service).



    Bin

    Wednesday, May 07, 2014 4:09 PM
  • Did you try to cal the MAPILogonEx without releasing the session and logging off? What Outlook version do you have installed on the problematic PC?
    Wednesday, May 07, 2014 4:32 PM
  • No, always call logoff and release before calling logon again.

    It happens on customer env.  I believe it is outlook 2010 sp2.


    Bin

    Wednesday, May 07, 2014 7:36 PM
  • Try to call MAPILogonEx without logging off.

    Do you get any errors if you just continue using old session objects?

    Wednesday, May 07, 2014 7:54 PM