![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I'm receiving the following COMException:
"Your server administrator has limited the number of items you can open simultaneously. Try closing messages you have opened or removing attachments and images from unsent messages you are composing." when I try to iterate thru a list of Contact Items. I've read a few posts on this same error message but I'm still unsure how of how to properly fix it. Here is my code: ListContactItem Results = new ListContactItem(); Outlook.Items Contacts = this.WcmsContactsMapiFolder.Items; Outlook.ContactItem Contact = (Outlook.ContactItem) Contacts.GetFirst(); do { ContactItem NewCont = ContactItem.FromOutlookContactItem(Contact, this.SifApp); Results.Add(NewCont); Marshal.ReleaseComObject(Contact); Contact = (Outlook.ContactItem)Contacts.GetNext(); } while (Contact != null); return Results; I've read posts that say you must call " Marshal.ReleaseComObject()" but that doesn't appear to be closing the connection. I've read posts that say to increase the simultaneous connection limit but that doesn't see right to me. I'm able to view the contact list in Outlook so it is reading it somehow. |
Ads |
#2
|
|||
|
|||
![]()
Declare NewCont outside the loop so you aren't creating an instance of it
each pass through the loop. Set both contact objects to null, if that's not enough to prevent the error then call Marshal.ReleaseComObject() on them. If that's not enough then call the GC and WaitForPendingFinalizers(). Do it in steps so you don't add more handling than the minimum needed. Using ReleaseComObject() and the garbage collection is expensive. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "spottedmahn" wrote in message ... I'm receiving the following COMException: "Your server administrator has limited the number of items you can open simultaneously. Try closing messages you have opened or removing attachments and images from unsent messages you are composing." when I try to iterate thru a list of Contact Items. I've read a few posts on this same error message but I'm still unsure how of how to properly fix it. Here is my code: ListContactItem Results = new ListContactItem(); Outlook.Items Contacts = this.WcmsContactsMapiFolder.Items; Outlook.ContactItem Contact = (Outlook.ContactItem) Contacts.GetFirst(); do { ContactItem NewCont = ContactItem.FromOutlookContactItem(Contact, this.SifApp); Results.Add(NewCont); Marshal.ReleaseComObject(Contact); Contact = (Outlook.ContactItem)Contacts.GetNext(); } while (Contact != null); return Results; I've read posts that say you must call " Marshal.ReleaseComObject()" but that doesn't appear to be closing the connection. I've read posts that say to increase the simultaneous connection limit but that doesn't see right to me. I'm able to view the contact list in Outlook so it is reading it somehow. |
#3
|
|||
|
|||
![]()
Hi Ken, thanks for the reply.
The point of the loop is to convert Outlook Contacts objects to My Custom Contact Objects so it doesn't make sense to declare NewCont outside the loop. Maybe I'm mis-understanding you? I've seen similar suggestions in other forum posts and it seems like a cross your fingers and hope solution which doesn't make me feel very comfortable. It seems like there should be a reliable way of "closing" objects that you open. Am I missing something? Thanks, Mike D. "Ken Slovak - [MVP - Outlook]" wrote: Declare NewCont outside the loop so you aren't creating an instance of it each pass through the loop. Set both contact objects to null, if that's not enough to prevent the error then call Marshal.ReleaseComObject() on them. If that's not enough then call the GC and WaitForPendingFinalizers(). Do it in steps so you don't add more handling than the minimum needed. Using ReleaseComObject() and the garbage collection is expensive. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm |
#4
|
|||
|
|||
![]()
Yes, if you don't follow the advice you've seen from me and other posters
you are missing something. If you follow the advice you won't have those problems. Declaring the NewCont object outside the loop creates only 1 of those objects. You just set it and reset it inside the loop. If you declare it inside the loop and the loop executes 200 times you just created 200 of those objects. You can still do what you want, and then have to use Marshal.ReleaseComObject() on each object plus setting each object to null, then calling GC and WaitForPendingFinalizers on each pass through the loop. That will also work, but the performance of loop execution will suffer a lot. What I recommended is a balance of getting the loop to work and having it work as fast as possible. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "spottedmahn" wrote in message ... Hi Ken, thanks for the reply. The point of the loop is to convert Outlook Contacts objects to My Custom Contact Objects so it doesn't make sense to declare NewCont outside the loop. Maybe I'm mis-understanding you? I've seen similar suggestions in other forum posts and it seems like a cross your fingers and hope solution which doesn't make me feel very comfortable. It seems like there should be a reliable way of "closing" objects that you open. Am I missing something? Thanks, Mike D. |
#5
|
|||
|
|||
![]()
Hi Ken, thanks again for the reply.
I'm still not clear on your analysis of declaring NewCont outside the loop. Whether I put NewCont inside or outside the loop N objects will be created. The point of the loop is to take a Outlook Contact and create a Custom Contact Object. Therefore for every Outlook Contact object there will be one Custom Contact Object. So if I have 200 Outlook Contacts in a MapiFolder the above code would return a ListCustomContactObject whose count is 200. Make sense? As for setting each object to null I'm unclear on how that would effect anything. With each iteration of the loop the variables are re-assigned to other objects. So on Pass 1 Contact = X, then on Pass 2 Contact = Y. Nothing points to X anymore. I'm not trying to be combative I'm just trying to understand. Thanks for you input, Mike D. "Ken Slovak - [MVP - Outlook]" wrote: Yes, if you don't follow the advice you've seen from me and other posters you are missing something. If you follow the advice you won't have those problems. Declaring the NewCont object outside the loop creates only 1 of those objects. You just set it and reset it inside the loop. If you declare it inside the loop and the loop executes 200 times you just created 200 of those objects. You can still do what you want, and then have to use Marshal.ReleaseComObject() on each object plus setting each object to null, then calling GC and WaitForPendingFinalizers on each pass through the loop. That will also work, but the performance of loop execution will suffer a lot. What I recommended is a balance of getting the loop to work and having it work as fast as possible. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm |
#6
|
|||
|
|||
![]()
If you declare an object outside the loop
Outlook.ContactItem NewCont = null; and then instantiate instances of it within the loop you are only creating one object. You are assigning an instance of that object each time through the loop, then you set it to null/release. Next time through you are just instantiating another instance of that object. If you declare the object inside the loop you create one object each pass through the loop, then instantiate it then release it. Those 2 are not identical scenarios. If you don't release the objects then they remain in memory until some undetermined time in the future when the garbage collector finally runs after the items go out of scope. The RPC channels remain committed until those objects are released. Therefore you get the errors you described. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "spottedmahn" wrote in message ... Hi Ken, thanks again for the reply. I'm still not clear on your analysis of declaring NewCont outside the loop. Whether I put NewCont inside or outside the loop N objects will be created. The point of the loop is to take a Outlook Contact and create a Custom Contact Object. Therefore for every Outlook Contact object there will be one Custom Contact Object. So if I have 200 Outlook Contacts in a MapiFolder the above code would return a ListCustomContactObject whose count is 200. Make sense? As for setting each object to null I'm unclear on how that would effect anything. With each iteration of the loop the variables are re-assigned to other objects. So on Pass 1 Contact = X, then on Pass 2 Contact = Y. Nothing points to X anymore. I'm not trying to be combative I'm just trying to understand. Thanks for you input, Mike D. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Limited number of columns | Pavel | Outlook - Calandaring | 0 | July 8th 08 06:34 PM |
Your server administrator has limited the number of items you can | Johan Verrept | Outlook and VBA | 3 | March 13th 08 04:57 PM |
Your server administrator has limited the number of items you can | Johan Verrept | Add-ins for Outlook | 3 | March 13th 08 04:57 PM |
When exporting Outlook 2007 Contacts inly a limited number go. | mcfarmer | Outlook - Using Contacts | 2 | October 26th 07 10:01 PM |
You server administrator has limited ... | Brian Ross | Outlook - General Queries | 1 | April 10th 07 03:07 PM |