Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q260141

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


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.

↑ Back to the top


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

↑ Back to the top


Keywords: kbmsg, kbprb, KB260141

↑ Back to the top

Article Info
Article ID : 260141
Revision : 6
Created on : 8/24/2005
Published on : 8/24/2005
Exists online : False
Views : 464