Stef Merlijn
asked on
Can't connect to Outlook via TOutlookApplication component
Hi,
One of our customers has a problem with synchronizing scheduler events from Outlook to our application.
Customer PC details: Windows 10, Outlook 2010.
Our application uses component "TOutlookApplication" to connect to Outlook.
When connecting to Outlook the user is asked to close Outlook before starting sync.
Does anybody have an idea how this can be solved?
One of our customers has a problem with synchronizing scheduler events from Outlook to our application.
Customer PC details: Windows 10, Outlook 2010.
Our application uses component "TOutlookApplication" to connect to Outlook.
When connecting to Outlook the user is asked to close Outlook before starting sync.
procedure TForm1.btStartImportClick(Sender: TObject);
var Calendar: MAPIFolder;
NmSpace: NameSpace;
begin
try
appOutlook.ConnectKind := ckRunningOrNew;
appOutlook.Connect;
try
NmSpace := appOutlook.GetNamespace('MAPI');
NmSpace.Logon('', '', False, False);
Calendar := NmSpace.GetDefaultFolder(olFolderCalendar);
ProgressBar1.Max := Calendar.Items.Count;
except
On E: EOleException do // uses ComObj
begin
E.Message := FullOleExceptionMessage(E);
ShowMessage(E.Message);
Exit;
end;
end;
finally
appOutlook.Disconnect;
end;
end;
The error which is given: Cannot connect to MS Outlook server is unavailable
Error code: -2147221231 80040111
Facility: ITF code: 4
Does anybody have an idea how this can be solved?
Hi, Make sure that your username and password are correct. try username like Domain\Username
ASKER
imkottees: There is no username or password given in my code, so I don't quite understand.
NmSpace.Logon('', '', False, False);
Also user doesn't have to login when he starts Outlook normally.
Try to comment (or delete) lines:
//appOutlook.ConnectKind := ckRunningOrNew;
//appOutlook.Connect;
ASKER
@Sinisa Vuk: Without those settings I get following EOleSysError:
"Uitvoeren vanaf de server is mislukt, ClassID: {0006F03A-0000-0000-C000-0 0000000004 6}."
This is when Outlook is NOT already running.
If I start Outlook before sync, than on my system the connection is established.
"Uitvoeren vanaf de server is mislukt, ClassID: {0006F03A-0000-0000-C000-0
This is when Outlook is NOT already running.
If I start Outlook before sync, than on my system the connection is established.
ASKER
No I don't. What does it do?
ASKER
I used to use this but it gave problems on some systems:
Try
appOutlook.ConnectKind := ckRunningOrNew;
appOutlook.Connect;
try
NmSpace := appOutlook.GetNamespace('MAPI');
NmSpace.Logon('', '', False, False);
Calendar := NmSpace.GetDefaultFolder(olFolderCalendar);
ProgressBar1.Max := Calendar.Items.Count;
except
Finally
appOutlook.Disconnect;
end;
ASKER
When I use following code I can only use it when Outlook is closed, otherwise I get the same connectionerror.
Outlook := CoOutlookApplication.Create;
NmSpace := Outlook.GetNamespace('MAPI');
NmSpace.Logon('', '', False, False);
Calendar := NmSpace.GetDefaultFolder(olFolderCalendar);
ProgressBar1.Max := Calendar.Items.Count;
Ahhh, you put TOutlookApplication component to form, right? So, that's why you don't have a create.
Hmm, if you put:
Hmm, if you put:
Outlook := CoOutlookApplication.Create;
Outlook.Connect;
NmSpace := Outlook.GetNamespace('MAPI');
NmSpace.Logon('', '', False, False);
...
?
ASKER
Outlook.Connect; -> undeclared identifier 'Connect'
ASKER
Can it be related that multiple instances of Outlook aren't allowed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The same error occurs when Outlook is running.
So it doesn't matter which way the connection is established.
So it doesn't matter which way the connection is established.
ASKER
As I see it, the connection is made correctly, so the error has to come from a different problem.
Does anybody have an idea how to track this down and solve it?
Does anybody have an idea how to track this down and solve it?
ASKER
Thanks for making sure connection was established correctly.
It turned out that a PDF plugin in Outlook kept some instance of Outlook running in the background even when it was closed. After de-installing the plugin the problem was solved.
It turned out that a PDF plugin in Outlook kept some instance of Outlook running in the background even when it was closed. After de-installing the plugin the problem was solved.