PRB: OpenMsgStore() and HrMailboxLogon() May Fail When You Open More Than 255 Mailboxes (260141)



The information in this article applies to:

  • Microsoft Exchange Server 4.0
  • Microsoft Exchange Server 4.0 SP1
  • Microsoft Exchange Server 4.0 SP2
  • Microsoft Exchange Server 4.0 SP3
  • Microsoft Exchange Server 4.0 SP4
  • Microsoft Exchange Server 4.0 SP5
  • Microsoft Exchange Server 5.0
  • Microsoft Exchange Server 5.5
  • Microsoft Extended Messaging Application Programming Interface (MAPI)

This article was previously published under Q260141

SYMPTOMS

If you attempt to open more than 255 mailboxes in a single process, you may receive an error.

With the Messaging Application Programming Interface (MAPI), you can open mailboxes by using the OpenMsgStore method or the HrMailboxLogon function. When you try to open too many mailboxes, the OpenMsgStore method returns the MAPI_E_FAILONEPROVIDER error, and the HrMailboxLogon function returns the MAPI_E_CALL_FAILED error.

NOTE: On success, OpenMsgStore and HRMailboxLogon both return S_OK and a valid IMsgStore interface.

CAUSE

This behavior occurs because MAPI communicates between a client program and the Microsoft Exchange Server through the Emsmdb32.dll transport provider. This provider uses Microsoft Remote Procedure Calls (RPC) to communicate with the server. A single byte holds the index of the logon object, which limits the number of logons in a single session and process to 255. In fact, the actual limit may be lower because some of the index values are reserved.

RESOLUTION

There are two ways to work around this behavior:
  • Structure your program so that the number of mailboxes open at one time never exceeds the limit. If possible, log on to one mailbox at a time, and release its interface when you are done. Once a mailbox is released, its index value can be reused. (See the "More Information" section for more details.) You can also structure the program to spawn subprocesses that each handle a portion of the mailboxes. The subprocesses do not exceed the limit individually, and the program as a whole can have access to all mailboxes simultaneously.
  • Create a special profile specifically for use by your program. On this profile, set PR_PROFILE_CONNECT_FLAGS to include the flag CONNECT_USE_SEPARATE_CONNECTION (0x4). This profile instructs MAPI to use a separate RPC connection for each logon. This approach is inefficient, however, and is not recommended.

STATUS

This behavior is by design.

MORE INFORMATION

Even if you structure your MAPI program to loop through mailboxes, releasing each message store interface after use, you may still encounter the limit. A message store connection cannot be released if any outstanding objects are open on the store. The most commonly leaked interfaces are IMAPITable, IMAPIFolder, and IMessage. Note that if you do loop through mailboxes on a server, you must release all interfaces in the reverse order from which they were obtained.

Under extreme circumstances, if you cannot locate the source of leaked interfaces, you can call the MAPIUninitialize function to cause MAPI to invalidate and recover all outstanding interfaces and memory.

REFERENCES

For additional information on opening mailboxes, click the article number below to view the article in the Microsoft Knowledge Base:

194627 HOWTO: Open Mailboxes with Privileged Access

For additional information about how to loop through mailboxes, click the article number below to view the article in the Microsoft Knowledge Base:

200160 HOWTO: Loop Through Mailboxes on Exchange Using GetMailboxTable


Modification Type:MinorLast Reviewed:8/24/2005
Keywords:kbMsg kbprb KB260141