Outlook Automation Automation Problem Out of Memory

  • Thread starter Thread starter MikeA
  • Start date Start date
M

MikeA

I'm not sure if I am posting to the right forum but I am having a problem
with accessing Contacts with Outlook Automation. The program works perfect
in Outlook 2003 but gives an error on another computer with Outlook 2002.
When I try and access the .Body I get an OLE Dispatch Error Code 4096 From
Microsoft Outlook Out Of Memory. I'm not sure if the problem is with
Outlook, the computer or perhaps I could change my programming code and how
I access the body in Outlook Contacts.

The code that gives the error is in VFP but it should be similar to VB so
here's a snapshot if it helps. I don't think it is a coding problem but I'm
thinking perhaps there might be another way to access the body which might
not give this error.

loOutlook = createobject('outlook.application')
loNS = loOutlook.GetNameSpace('MAPI')
loDF = loNS.GetDefaultFolder(olFolderContacts)
loItems = loDF.items

loItem = loItems.item(1)
? loItem.Body

Also, does anyone know offhand how to access the Email field(s).

Thanks,
Mike
 
If you are accessing Body in Outlook 2002 you are running into the Outlook
object model security. See http://www.outlookcode.com/article.aspx?id=52 for
an explanation and workarounds.

The email fields are also restricted and subject to the security. They are
item.EmailNAddress where N is a number from 1 to 3. If the user is on
Exchange server the email address or addresses corresponding to an Exchange
address won't have an SMTP format it will be returned in an Exchange
distinguished name format.
 
No - I don't think it is a security issue. I had them try and export the
calendar from my application to Outlook and it brings up the Outlook
security dialog. I then had them enter 10 minutes so there would be plenty
of time to then try and export contacts. It gets to around 110 of 700
contacts to export and then it errors out upon reading the body. I don't
get it. It reads the body for the first 100+ contacts and then errors out
and gives an "out of memory error." But, it seems to work just fine on my
Outlook 2003 but not on their Outlook 2002.

Mike
 
Is this running against an Exchange server mailbox? If so it might be the
RPC channel limit. That's usually set to 255 and is set in the registry on
the server. Once you exceed that number of open RPC channels you get various
errors including out of memory errors.

If you are looping to handle multiple items then that's likely the problem.
The fixes are to eliminate usage of multiple dot operators so Outlook
doesn't open internal variables for each dot operator, explicitly releasing
your objects each pass through the loop to close their RPC channels and if
necessary using a shorter loop called repeatedly.

Normally any open internal variables aren't released until you exit the
procedure where they were created as they go out of scope. In that case your
loop procedure might have to be called repeatedly, say once for every 50 or
100 items.
 
Okay - I have a LOT more information now. Here's what's going on and I do
not understand why but I have discovered that the version of Outlook is not
important at all.

I had said in my OP that it gets to around reading contact #110 and then
errors out. What is happening is the line:

? loItem.Body

is the one erroring out. Actually, I'm trying to read the body and it
errors out. Now, what is interesting is for the first 110 records it works
fine but errors out on record 111. The records are not the ones I'm trying
to import from my application but rather other records that were manually
entered in Outlook.

As it turns out, I had a similar proble on my computer. What happend was I
ran it through a loop and when I did this on my computer it worked fine:

loItem = loItems.item(1)
? loItem.Body

But, when I did this (all from the command prompt in VFP:

loItem = loItems.item(60)
? loItem.Body

It errors out. In fact, I can't read any properties at all for item 60.
But this line:

? loItems.count

returns 64. So, I can't understand why for some records (that were directly
entered by me in Outlook and not imported from my database application) it
errors out but for others it works fine. For now, my solution is to use an
ON ERROR command to trap the error and continue. But, I am a little
perplexed as to why some objects are not returning any values.

Any thoughts?

Thanks,
Mike
 
I have no idea other than maybe the items aren't of the correct type? If
that's not it then it may be corruption of some sort in the problem items.
 
If it is corruption (which is what I also suspected) is there some kind of
"pack" or "reindex" or "fix databases" command in Outlook?

Thanks,
Mike
 
Just the external applications ScanPST.exe and ScanOST.exe, both usually
located in the C:\I386 folder. You run those with Outlook closed, using the
one for whichever store type you're using.
 
Back
Top