Bug in Access 2003 ? Error after 380 CreateObject("MAPI.Session")

O

Ottar

I've made a program sorting incomming mail in public folder.

The function runs every minute by using the form.timer event.

In Access XP it runs for weeks, no problem. Access 2003 runs the same
code for 6 hours and stops.

I've found the problem to be the Set MySession =
CreateObject("MAPI.Session")

I've made a test program:
Function MAPI_Test()
Dim i As Integer
Dim OK As Boolean
Dim MySession As MAPI.Session
i = 0
OK = True
While (i < 2000) And OK
OK = MAPI_Logon(MySession)
If OK Then OK = MAPI_Logoff(MySession)
Debug.Print i
i = i + 1
DoEvents
Wend
End Function

In Access XP this runs until i = 2000

In Access 2003 the function stops after 380 iterations. The error is
E_MAPI_INVALID_OBJECT. I have to close down Access then i get "a new
qutoa" of 380.

I've downloaded latest fix'es from Microsoft.

Any ideas welcome!

Below is the Logon / Logoff functions used above.

Function MAPI_Logon(Session As MAPI.Session) As Boolean
Set Session = CreateObject("MAPI.Session")
On Error Resume Next
Session.Logon , , , , , , "my-server" & vbLf & "Administrator"
If Err.Number <> 0 Then MAPI_Logon = False Else MAPI_Logon = True
End Function

Function MAPI_Logoff(Session As MAPI.Session) As Boolean
On Error Resume Next
Session.Logoff
If Err.Number <> 0 Then MAPI_Logoff = False Else MAPI_Logoff = True
End Function
 
R

Ron Weiner

Ottar

It looks like you Dim the session variable in Function MAPI_Test, actually
instantiate it in MAPI_Login, but never destroy it anywhere. I think you'd
do better to Dim, Instantiate, and Destroy the session variable in the
MAPI_Test function. In effect what you are doing is creating a massive
memory leak. Eventually there is not enough memory to instantiate another
session and your routine fails. Try changing the MAPI_Test function so it
handles the creation and destruction of the session object.

Function MAPI_Test()
Dim i As Integer
Dim OK As Boolean
Dim MySession As MAPI.Session
i = 0
OK = True
While (i < 2000) And OK
Set MySession = CreateObject("MAPI.Session")
OK = MAPI_Logon(MySession)
If OK Then OK = MAPI_Logoff(MySession)
Debug.Print i
i = i + 1
Set MySession = Nothing
DoEvents
Wend
End Function

Remove the line
Set Session = CreateObject("MAPI.Session")
from MAPI_Logon and see how things go.

Ron W
 
O

Ottar L. Osen

Even without logging in / out (see small function below) you get the same
error: 80040108

Function MAPI_Test2()
Dim i As Integer
Dim MySession As MAPI.Session
i = 0
While (i < 2000)
Set MySession = CreateObject("MAPI.Session")
Debug.Print i
i = i + 1
Set MySession = Nothing
DoEvents
Wend
End Function

Any other ideas?

Best regards

Ottar
 
C

CDB

1. Why are you trying to open 2,000 external instances of a Mapi session in
succession? It seems a pointless test - except to find out where the
stupidity point is. 380 sounds pretty good.

2. Place the session lines in a separate procedure so that VBA cleans up
after each termination.

3. Don't repost within a few minutes - exercise patience.

4, On which line does the error arise?

Clive
 
O

Ottar L. Osen

Hm, you probably did not read part 1 of my message, its quoted below, but
I'll be nice and copy it up here for you:

As you see loging On and Off are done in external functions, logon procedure
creates object. I've not included the whole program, I've included a program
that illustrates the problem. Finally I boiled the problem down to the small
program you find stupid.
My problem is that whatever I do after 380 object creations it fails. Not so
in XP, just in 2003.
If you have a solution to my problem I am glad to hear it.
Yours Ottar
 
R

Ragnar Midtskogen

Hello Ottar,

No solutions to your problem, just a couple of comments on NG etiquette
1. Cross posting is considered rude, not everone are subscribed to the same
groups you are, so they get messages about groupos that could not be
resolved..
2. Sarcasm usually backfires. You are asking for help, annoying your
potential helpers is also rude.
3. Copying previous post is not neccessary, it just wastes space on the news
server.

Ragnar
 
O

Ottar L. Osen

My appologies for breaking NG etiquette ! !
Regarding crossposting, I was not sure which group the problem belonged to.
Next time I'll post individually.
Regarding copying previous post, yes I agree in general, but it was done to
clarify (at the bottom is Outlook Express default).
Reagrding sarcasm, again you are right, but beeing called stupid:
1. Why are you trying to open 2,000 external instances of a Mapi session
in succession? It seems a pointless test - except to find out where the
stupidity point is. 380 sounds pretty good.

for asking relevant questions tickled my humor nerve... Again I'm sorry.

I've not found a solution for my problem yet, and I've tested on several
PC's. Anyone know how to report bug's to Microsoft?

Ottar
 
D

Dirk Goldgar

Ottar L. Osen said:
My appologies for breaking NG etiquette ! !
Regarding crossposting, I was not sure which group the problem
belonged to. Next time I'll post individually.

No, please don't! *If* you have determined that multiple newsgroups are
relevant to your question (they usually aren't, but may be), then it is
much better -- and generally accepted -- to crosspost to those groups in
a single message, rather than post the same message independently to
multiple groups. Most newsreader programs recognize crossposts, so that
if a user marks your message as read in one group, the message will also
be marked as read in any crossposted groups. Also, replies to the
crossposted message appear in all groups, so that readers (and you) can
tell whether a question has been answered or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top