I spent yesterday my fair share of hours trying to get the Exchange/Outlook MAPI Installable ISAM for the JET engine to work through System.Data.OleDb. What we needed to do was pretty simple: Just do a couple of queries on the user's Outlook Inbox folder or Address book and display a few fields from there.

There are quite a few samples and articles about using the Exchange IISAM through jet around, most of them old samples in VB6 using DAO and ADO (understandably). And they actually worked. However, when I tried to do the same from .NET I kept getting the following exception:

System.Data.OleDb.OleDbException: There are no MAPI clients installed on this machine. Install a MAPI client (like Outlook) on this machine.

After much fiddling and much frustration, I figured out what the problem was: The Exchange/Outlook IISAM engines need to be called from an STA Thread. That was not a problem for the many VB6-based samples because VB code was always in the STA, but in .NET threads by default are joined to the process' MTA.

Just thought I might save someone a little frustration by point this out. Boy, I had almost forgotten how "fun" COM threading models were!

Technorati tags: , , , ,

Tomas Restrepo

Software developer located in Colombia. Sr. PFE at Microsoft.